added Vector_zeroEnd() function
[util-vserver.git] / util-vserver / ensc_wrappers / wrappers-unistd.hc
1 // $Id$    --*- 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   size_t        res = read(fd, ptr, len);
89   FatalErrnoError((ssize_t)(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   size_t        res = write(fd, ptr, len);
98   FatalErrnoError((ssize_t)(res)==-1, "write()");
99
100   return res;
101 }
102
103 inline static WRAPPER_DECL void
104 Ereadlink(const char *path, char *buf, size_t bufsiz)
105 {
106   FatalErrnoError(readlink(path, buf, bufsiz)==-1, "readlink()");
107 }
108
109 inline static WRAPPER_DECL void
110 EreadlinkD(const char *path, char *buf, size_t bufsiz)
111 {
112   ENSC_DETAIL1(msg, "readlink", path, 1);
113   FatalErrnoError(readlink(path, buf, bufsiz)==-1, msg);
114 }
115
116 inline static WRAPPER_DECL void
117 Esymlink(const char *oldpath, const char *newpath)
118 {
119   FatalErrnoError(symlink(oldpath, newpath)==-1, "symlink()");
120 }
121
122 inline static WRAPPER_DECL void
123 EsymlinkD(const char *oldpath, const char *newpath)
124 {
125   ENSC_DETAIL2(msg, "symlink", oldpath, newpath, 1, 1);
126   FatalErrnoError(symlink(oldpath, newpath)==-1, msg);
127 }
128
129 inline static WRAPPER_DECL void
130 Eunlink(char const *pathname)
131 {
132   FatalErrnoError(unlink(pathname)==-1, "unlink()");
133 }
134
135 inline static void
136 Esetuid(uid_t uid)
137 {
138   FatalErrnoError(setuid(uid)==-1, "setuid()");
139 }
140
141 inline static void
142 Esetgid(gid_t gid)
143 {
144   FatalErrnoError(setgid(gid)==-1, "setgid()");
145 }
146
147 #if defined(_GRP_H) && (defined(__USE_BSD) || defined(__dietlibc__))
148 inline static void
149 Esetgroups(size_t size, const gid_t *list)
150 {
151   FatalErrnoError(setgroups(size, list)==-1, "setgroups()");
152 }
153 #endif
154
155 inline static WRAPPER_DECL int
156 Edup2(int oldfd, int newfd)
157 {
158   register int          res = dup2(oldfd, newfd);
159   FatalErrnoError(res==-1, "dup2()");
160
161   return res;
162 }
163
164 inline static WRAPPER_DECL int
165 Edup(int fd)
166 {
167   register int          res = dup(fd);
168   FatalErrnoError(res==-1, "dup()");
169
170   return res;
171 }
172
173 inline static WRAPPER_DECL pid_t
174 Esetsid()
175 {
176   register pid_t const  res = setsid();
177   FatalErrnoError(res==-1, "setsid()");
178
179   return res;
180 }
181
182 inline static WRAPPER_DECL int
183 Emkstemp(char *template)
184 {
185   int           res = mkstemp(template);
186   FatalErrnoError(res==-1, "mkstemp()");
187   return res;
188 }
189
190 inline static WRAPPER_DECL off_t
191 Elseek(int fildes, off_t offset, int whence)
192 {
193   off_t         res = lseek(fildes, offset, whence);
194   FatalErrnoError(res==(off_t)-1, "lseek()");
195   return res;
196 }