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 NORETURN void
47 Eexecv(char const *path, char *argv[])
50 FatalErrnoErrorFail("execv()");
53 inline static WRAPPER_DECL NORETURN void
54 Eexecvp(char const *path, char *argv[])
57 FatalErrnoErrorFail("execvp()");
60 inline static WRAPPER_DECL NORETURN void
61 EexecvpD(char const *path, char *argv[])
65 ENSC_DETAIL1(msg, "execvp", path, 1);
66 FatalErrnoErrorFail(msg);
70 inline static WRAPPER_DECL void
73 FatalErrnoError(pipe(filedes)==-1, "pipe()");
76 inline static WRAPPER_DECL pid_t
81 FatalErrnoError(res==-1, "fork()");
85 inline static WRAPPER_DECL size_t
86 Eread(int fd, void *ptr, size_t len)
88 size_t res = read(fd, ptr, len);
89 FatalErrnoError((ssize_t)(res)==-1, "read()");
94 inline static WRAPPER_DECL size_t
95 Ewrite(int fd, void const *ptr, size_t len)
97 size_t res = write(fd, ptr, len);
98 FatalErrnoError((ssize_t)(res)==-1, "write()");
103 inline static WRAPPER_DECL size_t
104 Ereadlink(const char *path, char *buf, size_t bufsiz)
106 size_t res = readlink(path, buf, bufsiz);
107 FatalErrnoError((ssize_t)(res)==-1, "readlink()");
112 inline static WRAPPER_DECL size_t
113 EreadlinkD(const char *path, char *buf, size_t bufsiz)
115 size_t res = readlink(path, buf, bufsiz);
116 ENSC_DETAIL1(msg, "readlink", path, 1);
117 FatalErrnoError((ssize_t)(res)==-1, msg);
122 inline static WRAPPER_DECL void
123 Esymlink(const char *oldpath, const char *newpath)
125 FatalErrnoError(symlink(oldpath, newpath)==-1, "symlink()");
128 inline static WRAPPER_DECL void
129 EsymlinkD(const char *oldpath, const char *newpath)
131 ENSC_DETAIL2(msg, "symlink", oldpath, newpath, 1, 1);
132 FatalErrnoError(symlink(oldpath, newpath)==-1, msg);
135 inline static WRAPPER_DECL void
136 Eunlink(char const *pathname)
138 FatalErrnoError(unlink(pathname)==-1, "unlink()");
144 FatalErrnoError(setuid(uid)==-1, "setuid()");
150 FatalErrnoError(setgid(gid)==-1, "setgid()");
153 #if defined(_GRP_H) && (defined(__USE_BSD) || defined(__dietlibc__))
155 Esetgroups(size_t size, const gid_t *list)
157 FatalErrnoError(setgroups(size, list)==-1, "setgroups()");
161 inline static WRAPPER_DECL int
162 Edup2(int oldfd, int newfd)
164 register int res = dup2(oldfd, newfd);
165 FatalErrnoError(res==-1, "dup2()");
170 inline static WRAPPER_DECL int
173 register int res = dup(fd);
174 FatalErrnoError(res==-1, "dup()");
179 inline static WRAPPER_DECL pid_t
182 register pid_t const res = setsid();
183 FatalErrnoError(res==-1, "setsid()");
188 inline static WRAPPER_DECL int
189 Emkstemp(char *template)
191 int res = mkstemp(template);
192 FatalErrnoError(res==-1, "mkstemp()");
196 inline static WRAPPER_DECL off_t
197 Elseek(int fildes, off_t offset, int whence)
199 off_t res = lseek(fildes, offset, whence);
200 FatalErrnoError(res==(off_t)-1, "lseek()");
204 inline static WRAPPER_DECL void
207 FatalErrnoError(nice(n)==-1, "nice()");
210 inline static WRAPPER_DECL void
211 Etruncate(const char *path, off_t length)
213 FatalErrnoError(truncate(path,length)==-1, "truncate()");
216 inline static WRAPPER_DECL void
217 Eftruncate(int fd, off_t length)
219 FatalErrnoError(ftruncate(fd,length)==-1, "ftruncate()");