register generated files so that they
[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   FatalErrnoError(execv(path,argv)==-1, "execv()");
50 }
51
52 inline static WRAPPER_DECL NORETURN void
53 Eexecvp(char const *path, char *argv[])
54 {
55   FatalErrnoError(execvp(path,argv)==-1, "execvp()");
56 }
57
58 inline static WRAPPER_DECL void
59 Epipe(int filedes[2])
60 {
61   FatalErrnoError(pipe(filedes)==-1, "pipe()");
62 }
63
64 inline static WRAPPER_DECL pid_t
65 Efork()
66 {
67   pid_t         res;
68   res = fork();
69   FatalErrnoError(res==-1, "fork()");
70   return res;
71 }
72
73 inline static WRAPPER_DECL size_t
74 Eread(int fd, void *ptr, size_t len)
75 {
76   size_t        res = read(fd, ptr, len);
77   FatalErrnoError((ssize_t)(res)==-1, "read()");
78
79   return res;
80 }
81
82 inline static WRAPPER_DECL size_t
83 Ewrite(int fd, void const *ptr, size_t len)
84 {
85   size_t        res = write(fd, ptr, len);
86   FatalErrnoError((ssize_t)(res)==-1, "write()");
87
88   return res;
89 }
90
91 inline static WRAPPER_DECL void
92 Ereadlink(const char *path, char *buf, size_t bufsiz)
93 {
94   FatalErrnoError(readlink(path, buf, bufsiz)==-1, "readlink()");
95 }
96
97 inline static WRAPPER_DECL void
98 Esymlink(const char *oldpath, const char *newpath)
99 {
100   FatalErrnoError(symlink(oldpath, newpath)==-1, "symlink()");
101 }
102
103 inline static WRAPPER_DECL void
104 Eunlink(char const *pathname)
105 {
106   FatalErrnoError(unlink(pathname)==-1, "unlink()");
107 }
108
109 inline static void
110 Esetuid(uid_t uid)
111 {
112   FatalErrnoError(setuid(uid)==-1, "setuid()");
113 }
114
115 inline static void
116 Esetgid(gid_t gid)
117 {
118   FatalErrnoError(setgid(gid)==-1, "setgid()");
119 }
120
121 #if defined(_GRP_H) && (defined(__USE_BSD) || defined(__dietlibc__))
122 inline static void
123 Esetgroups(size_t size, const gid_t *list)
124 {
125   FatalErrnoError(setgroups(size, list)==-1, "setgroups()");
126 }
127 #endif
128
129 inline static WRAPPER_DECL int
130 Edup2(int oldfd, int newfd)
131 {
132   register int          res = dup2(oldfd, newfd);
133   FatalErrnoError(res==-1, "dup2()");
134
135   return res;
136 }
137
138 inline static WRAPPER_DECL pid_t
139 Esetsid()
140 {
141   register pid_t const  res = setsid();
142   FatalErrnoError(res==-1, "setsid()");
143
144   return res;
145 }
146
147 inline static WRAPPER_DECL int
148 Emkstemp(char *template)
149 {
150   int           res = mkstemp(template);
151   FatalErrnoError(res==-1, "mkstemp()");
152   return res;
153 }
154
155 inline static WRAPPER_DECL off_t
156 Elseek(int fildes, off_t offset, int whence)
157 {
158   off_t         res = lseek(fildes, offset, whence);
159   FatalErrnoError(res==(off_t)-1, "lseek()");
160   return res;
161 }