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