3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #ifndef H_ENSC_IN_WRAPPERS_H
19 # error wrappers_handler.hc can not be used in this way
22 inline static WRAPPER_DECL void
25 FatalErrnoError(close(s)==-1, "close()");
28 inline static WRAPPER_DECL void
29 Echdir(char const path[])
31 FatalErrnoError(chdir(path)==-1, "chdir()");
34 inline static WRAPPER_DECL void
37 FatalErrnoError(fchdir(fd)==-1, "fchdir()");
40 inline static WRAPPER_DECL void
41 Echroot(char const path[])
43 FatalErrnoError(chroot(path)==-1, "chroot()");
46 inline static WRAPPER_DECL void
47 Eexecv(char const *path, char *argv[])
49 FatalErrnoError(execv(path,argv)==-1, "execv()");
52 inline static WRAPPER_DECL void
55 FatalErrnoError(pipe(filedes)==-1, "pipe()");
58 inline static WRAPPER_DECL pid_t
63 FatalErrnoError(res==-1, "fork()");
67 inline static WRAPPER_DECL size_t
68 Eread(int fd, void *ptr, size_t len)
70 size_t res = read(fd, ptr, len);
71 FatalErrnoError((ssize_t)(res)==-1, "read()");
76 inline static WRAPPER_DECL size_t
77 Ewrite(int fd, void const *ptr, size_t len)
79 size_t res = write(fd, ptr, len);
80 FatalErrnoError((ssize_t)(res)==-1, "write()");
85 inline static WRAPPER_DECL void
86 Ereadlink(const char *path, char *buf, size_t bufsiz)
88 FatalErrnoError(readlink(path, buf, bufsiz)==-1, "readlink()");
91 inline static WRAPPER_DECL void
92 Esymlink(const char *oldpath, const char *newpath)
94 FatalErrnoError(symlink(oldpath, newpath)==-1, "symlink()");
97 inline static WRAPPER_DECL void
98 Eunlink(char const *pathname)
100 FatalErrnoError(unlink(pathname)==-1, "unlink()");
106 FatalErrnoError(setuid(uid)==-1, "setuid()");
112 FatalErrnoError(setgid(gid)==-1, "setgid()");
115 #if defined(_GRP_H) && (defined(__USE_BSD) || defined(__dietlibc__))
117 Esetgroups(size_t size, const gid_t *list)
119 FatalErrnoError(setgroups(size, list)==-1, "setgroups()");
123 inline static WRAPPER_DECL int
124 Edup2(int oldfd, int newfd)
126 register int res = dup2(oldfd, newfd);
127 FatalErrnoError(res==-1, "dup2()");
132 inline static WRAPPER_DECL pid_t
135 register pid_t const res = setsid();
136 FatalErrnoError(res==-1, "setsid()");
141 inline static WRAPPER_DECL int
142 Emkstemp(char *template)
144 int res = mkstemp(template);
145 FatalErrnoError(res==-1, "mkstemp()");
149 inline static WRAPPER_DECL off_t
150 Elseek(int fildes, off_t offset, int whence)
152 off_t res = lseek(fildes, offset, whence);
153 FatalErrnoError(res==(off_t)-1, "lseek()");