merge with 0.30.213
[util-vserver.git] / ensc_wrappers / wrappers-unistd.hc
1 // $Id: wrappers-unistd.hc 2467 2007-01-21 18:26:45Z dhozac $    --*- c -*--
2
3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 //  
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.
8 //  
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.
13 //  
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.
17
18 #ifndef H_ENSC_IN_WRAPPERS_H
19 #  error wrappers_handler.hc can not be used in this way
20 #endif
21
22 inline static WRAPPER_DECL void
23 Eclose(int s)
24 {
25   FatalErrnoError(close(s)==-1, "close()");
26 }
27
28 inline static WRAPPER_DECL void
29 Echdir(char const path[])
30 {
31   FatalErrnoError(chdir(path)==-1, "chdir()");
32 }
33
34 inline static WRAPPER_DECL void
35 Efchdir(int fd)
36 {
37   FatalErrnoError(fchdir(fd)==-1, "fchdir()");
38 }
39
40 inline static WRAPPER_DECL void
41 Echroot(char const path[])
42 {
43   FatalErrnoError(chroot(path)==-1, "chroot()");
44 }
45
46 inline static WRAPPER_DECL NORETURN void
47 Eexecv(char const *path, char *argv[])
48 {
49   execv(path,argv);
50   FatalErrnoErrorFail("execv()");
51 }
52
53 inline static WRAPPER_DECL NORETURN void
54 Eexecvp(char const *path, char *argv[])
55 {
56   execvp(path,argv);
57   FatalErrnoErrorFail("execvp()");
58 }
59
60 inline static WRAPPER_DECL NORETURN void
61 EexecvpD(char const *path, char *argv[])
62 {
63   execvp(path,argv);
64   {
65     ENSC_DETAIL1(msg, "execvp", path, 1);
66     FatalErrnoErrorFail(msg);
67   }
68 }
69
70 inline static WRAPPER_DECL void
71 Epipe(int filedes[2])
72 {
73   FatalErrnoError(pipe(filedes)==-1, "pipe()");
74 }
75
76 inline static WRAPPER_DECL pid_t
77 Efork()
78 {
79   pid_t         res;
80   res = fork();
81   FatalErrnoError(res==-1, "fork()");
82   return res;
83 }
84
85 inline static WRAPPER_DECL size_t
86 Eread(int fd, void *ptr, size_t len)
87 {
88   ssize_t       res = read(fd, ptr, len);
89   FatalErrnoError(res==-1, "read()");
90
91   return res;
92 }
93
94 inline static WRAPPER_DECL size_t
95 Ewrite(int fd, void const *ptr, size_t len)
96 {
97   ssize_t       res = write(fd, ptr, len);
98   FatalErrnoError(res==-1, "write()");
99
100   return res;
101 }
102
103 inline static WRAPPER_DECL size_t
104 Ereadlink(const char *path, char *buf, size_t bufsiz)
105 {
106   ssize_t       res = readlink(path, buf, bufsiz);
107   FatalErrnoError(res==-1, "readlink()");
108
109   return res;
110 }
111
112 inline static WRAPPER_DECL size_t
113 EreadlinkD(const char *path, char *buf, size_t bufsiz)
114 {
115   ssize_t       res = readlink(path, buf, bufsiz);
116   ENSC_DETAIL1(msg, "readlink", path, 1);
117   FatalErrnoError((ssize_t)(res)==-1, msg);
118
119   return res;
120 }
121
122 inline static WRAPPER_DECL void
123 Esymlink(const char *oldpath, const char *newpath)
124 {
125   FatalErrnoError(symlink(oldpath, newpath)==-1, "symlink()");
126 }
127
128 inline static WRAPPER_DECL void
129 EsymlinkD(const char *oldpath, const char *newpath)
130 {
131   ENSC_DETAIL2(msg, "symlink", oldpath, newpath, 1, 1);
132   FatalErrnoError(symlink(oldpath, newpath)==-1, msg);
133 }
134
135 inline static WRAPPER_DECL void
136 Eunlink(char const *pathname)
137 {
138   FatalErrnoError(unlink(pathname)==-1, "unlink()");
139 }
140
141 inline static WRAPPER_DECL void
142 Elink(char const *oldpath, char const *newpath)
143 {
144   FatalErrnoError(link(oldpath, newpath)==-1, "link()");
145 }
146
147 inline static void
148 Esetuid(uid_t uid)
149 {
150   FatalErrnoError(setuid(uid)==-1, "setuid()");
151 }
152
153 inline static void
154 Esetgid(gid_t gid)
155 {
156   FatalErrnoError(setgid(gid)==-1, "setgid()");
157 }
158
159 #if defined(_GRP_H) && (defined(__USE_BSD) || defined(__dietlibc__))
160 inline static void
161 Esetgroups(size_t size, const gid_t *list)
162 {
163   FatalErrnoError(setgroups(size, list)==-1, "setgroups()");
164 }
165
166 inline static void
167 Einitgroups(const char *user, gid_t group)
168 {
169   FatalErrnoError(initgroups(user, group)==-1, "initgroups()");
170 }
171 #endif
172
173 inline static WRAPPER_DECL int
174 Edup2(int oldfd, int newfd)
175 {
176   register int          res = dup2(oldfd, newfd);
177   FatalErrnoError(res==-1, "dup2()");
178
179   return res;
180 }
181
182 inline static WRAPPER_DECL int
183 Edup(int fd)
184 {
185   register int          res = dup(fd);
186   FatalErrnoError(res==-1, "dup()");
187
188   return res;
189 }
190
191 inline static WRAPPER_DECL pid_t
192 Esetsid()
193 {
194   register pid_t const  res = setsid();
195   FatalErrnoError(res==-1, "setsid()");
196
197   return res;
198 }
199
200 inline static WRAPPER_DECL int
201 Emkstemp(char *template)
202 {
203   int           res = mkstemp(template);
204   FatalErrnoError(res==-1, "mkstemp()");
205   return res;
206 }
207
208 inline static WRAPPER_DECL off_t
209 Elseek(int fildes, off_t offset, int whence)
210 {
211   off_t         res = lseek(fildes, offset, whence);
212   FatalErrnoError(res==(off_t)-1, "lseek()");
213   return res;
214 }
215
216 inline static WRAPPER_DECL void
217 Enice(int n)
218 {
219   FatalErrnoError(nice(n)==-1, "nice()");
220 }
221
222 inline static WRAPPER_DECL void
223 Etruncate(const char *path, off_t length)
224 {
225   FatalErrnoError(truncate(path,length)==-1, "truncate()");
226 }
227
228 inline static WRAPPER_DECL void
229 Eftruncate(int fd, off_t length)
230 {
231   FatalErrnoError(ftruncate(fd,length)==-1, "ftruncate()");
232 }