Mercurial > hg > toybox
annotate lib/xwrap.c @ 1423:8059cfd67acd draft
Building busybox from source needs find -not (a synonym for posix's "!").
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 05 Aug 2014 19:32:44 -0500 |
parents | 9d760c092c41 |
children | 2f9bc9495144 |
rev | line source |
---|---|
951 | 1 /* xwrap.c - wrappers around existing library functions. |
2 * | |
3 * Functions with the x prefix are wrappers that either succeed or kill the | |
4 * program with an error message, but never return failure. They usually have | |
5 * the same arguments and return value as the function they wrap. | |
6 * | |
7 * Copyright 2006 Rob Landley <rob@landley.net> | |
8 */ | |
9 | |
10 #include "toys.h" | |
11 | |
12 // Strcpy with size checking: exit if there's not enough space for the string. | |
13 void xstrncpy(char *dest, char *src, size_t size) | |
14 { | |
1105
1bca28705a87
Give xstrncpy() a more informative error message.
Rob Landley <rob@landley.net>
parents:
1053
diff
changeset
|
15 if (strlen(src)+1 > size) error_exit("'%s' > %ld bytes", src, (long)size); |
951 | 16 strcpy(dest, src); |
17 } | |
18 | |
19 void xexit(void) | |
20 { | |
21 if (toys.rebound) longjmp(*toys.rebound, 1); | |
22 else exit(toys.exitval); | |
23 } | |
24 | |
25 // Die unless we can allocate memory. | |
26 void *xmalloc(size_t size) | |
27 { | |
28 void *ret = malloc(size); | |
29 if (!ret) error_exit("xmalloc"); | |
30 | |
31 return ret; | |
32 } | |
33 | |
34 // Die unless we can allocate prezeroed memory. | |
35 void *xzalloc(size_t size) | |
36 { | |
37 void *ret = xmalloc(size); | |
38 memset(ret, 0, size); | |
39 return ret; | |
40 } | |
41 | |
42 // Die unless we can change the size of an existing allocation, possibly | |
43 // moving it. (Notice different arguments from libc function.) | |
44 void *xrealloc(void *ptr, size_t size) | |
45 { | |
46 ptr = realloc(ptr, size); | |
47 if (!ptr) error_exit("xrealloc"); | |
48 | |
49 return ptr; | |
50 } | |
51 | |
52 // Die unless we can allocate a copy of this many bytes of string. | |
53 char *xstrndup(char *s, size_t n) | |
54 { | |
55 char *ret = xmalloc(++n); | |
56 strncpy(ret, s, n); | |
57 ret[--n]=0; | |
58 | |
59 return ret; | |
60 } | |
61 | |
62 // Die unless we can allocate a copy of this string. | |
63 char *xstrdup(char *s) | |
64 { | |
65 return xstrndup(s, strlen(s)); | |
66 } | |
67 | |
68 // Die unless we can allocate enough space to sprintf() into. | |
1183
0752b2d58909
Rename xmsprintf() to just xmprintf().
Rob Landley <rob@landley.net>
parents:
1170
diff
changeset
|
69 char *xmprintf(char *format, ...) |
951 | 70 { |
71 va_list va, va2; | |
72 int len; | |
73 char *ret; | |
74 | |
75 va_start(va, format); | |
76 va_copy(va2, va); | |
77 | |
78 // How long is it? | |
79 len = vsnprintf(0, 0, format, va); | |
80 len++; | |
81 va_end(va); | |
82 | |
83 // Allocate and do the sprintf() | |
84 ret = xmalloc(len); | |
85 vsnprintf(ret, len, format, va2); | |
86 va_end(va2); | |
87 | |
88 return ret; | |
89 } | |
90 | |
91 void xprintf(char *format, ...) | |
92 { | |
93 va_list va; | |
94 va_start(va, format); | |
95 | |
96 vprintf(format, va); | |
1318
955169e818d0
Isaac Dunham suggested xprintf() should call fflush() instead of ferror(), and posix-2008 doesn't say if fflush() covers ferror() (or can return success when the stream's error state is set), so call both.
Rob Landley <rob@landley.net>
parents:
1235
diff
changeset
|
97 if (fflush(stdout) || ferror(stdout)) perror_exit("write"); |
951 | 98 } |
99 | |
100 void xputs(char *s) | |
101 { | |
1318
955169e818d0
Isaac Dunham suggested xprintf() should call fflush() instead of ferror(), and posix-2008 doesn't say if fflush() covers ferror() (or can return success when the stream's error state is set), so call both.
Rob Landley <rob@landley.net>
parents:
1235
diff
changeset
|
102 if (EOF == puts(s) || fflush(stdout) || ferror(stdout)) perror_exit("write"); |
951 | 103 } |
104 | |
105 void xputc(char c) | |
106 { | |
1318
955169e818d0
Isaac Dunham suggested xprintf() should call fflush() instead of ferror(), and posix-2008 doesn't say if fflush() covers ferror() (or can return success when the stream's error state is set), so call both.
Rob Landley <rob@landley.net>
parents:
1235
diff
changeset
|
107 if (EOF == fputc(c, stdout) || fflush(stdout) || ferror(stdout)) |
955169e818d0
Isaac Dunham suggested xprintf() should call fflush() instead of ferror(), and posix-2008 doesn't say if fflush() covers ferror() (or can return success when the stream's error state is set), so call both.
Rob Landley <rob@landley.net>
parents:
1235
diff
changeset
|
108 perror_exit("write"); |
951 | 109 } |
110 | |
111 void xflush(void) | |
112 { | |
1318
955169e818d0
Isaac Dunham suggested xprintf() should call fflush() instead of ferror(), and posix-2008 doesn't say if fflush() covers ferror() (or can return success when the stream's error state is set), so call both.
Rob Landley <rob@landley.net>
parents:
1235
diff
changeset
|
113 if (fflush(stdout) || ferror(stdout)) perror_exit("write");; |
951 | 114 } |
115 | |
1327
85f297591693
Introduce xfork() and make commands use it, and make some WEXITSTATUS() use WIFEXITED() and WTERMSIG()+127.
Rob Landley <rob@landley.net>
parents:
1318
diff
changeset
|
116 pid_t xfork(void) |
85f297591693
Introduce xfork() and make commands use it, and make some WEXITSTATUS() use WIFEXITED() and WTERMSIG()+127.
Rob Landley <rob@landley.net>
parents:
1318
diff
changeset
|
117 { |
85f297591693
Introduce xfork() and make commands use it, and make some WEXITSTATUS() use WIFEXITED() and WTERMSIG()+127.
Rob Landley <rob@landley.net>
parents:
1318
diff
changeset
|
118 pid_t pid = fork(); |
85f297591693
Introduce xfork() and make commands use it, and make some WEXITSTATUS() use WIFEXITED() and WTERMSIG()+127.
Rob Landley <rob@landley.net>
parents:
1318
diff
changeset
|
119 |
85f297591693
Introduce xfork() and make commands use it, and make some WEXITSTATUS() use WIFEXITED() and WTERMSIG()+127.
Rob Landley <rob@landley.net>
parents:
1318
diff
changeset
|
120 if (pid < 0) perror_exit("fork"); |
85f297591693
Introduce xfork() and make commands use it, and make some WEXITSTATUS() use WIFEXITED() and WTERMSIG()+127.
Rob Landley <rob@landley.net>
parents:
1318
diff
changeset
|
121 |
85f297591693
Introduce xfork() and make commands use it, and make some WEXITSTATUS() use WIFEXITED() and WTERMSIG()+127.
Rob Landley <rob@landley.net>
parents:
1318
diff
changeset
|
122 return pid; |
85f297591693
Introduce xfork() and make commands use it, and make some WEXITSTATUS() use WIFEXITED() and WTERMSIG()+127.
Rob Landley <rob@landley.net>
parents:
1318
diff
changeset
|
123 } |
85f297591693
Introduce xfork() and make commands use it, and make some WEXITSTATUS() use WIFEXITED() and WTERMSIG()+127.
Rob Landley <rob@landley.net>
parents:
1318
diff
changeset
|
124 |
952
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
125 // Call xexec with a chunk of optargs, starting at skip. (You can't just |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
126 // call xexec() directly because toy_init() frees optargs.) |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
127 void xexec_optargs(int skip) |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
128 { |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
129 char **s = toys.optargs; |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
130 |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
131 toys.optargs = 0; |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
132 xexec(s+skip); |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
133 } |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
134 |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
135 |
951 | 136 // Die unless we can exec argv[] (or run builtin command). Note that anything |
137 // with a path isn't a builtin, so /bin/sh won't match the builtin sh. | |
138 void xexec(char **argv) | |
139 { | |
1032
40d0c96a8e89
Add scripts/single.sh to build individual non-multiplexed standalone commands.
Rob Landley <rob@landley.net>
parents:
1028
diff
changeset
|
140 if (CFG_TOYBOX) toy_exec(argv); |
951 | 141 execvp(argv[0], argv); |
142 | |
143 perror_exit("exec %s", argv[0]); | |
144 } | |
145 | |
1334
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
146 // Spawn child process, capturing stdin/stdout. |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
147 // argv[]: command to exec. If null, child returns to original program. |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
148 // pipes[]: stdin, stdout of new process. If null, block and wait for child. |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
149 // return: pid of child process |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
150 pid_t xpopen(char **argv, int *pipes) |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
151 { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
152 int cestnepasun[4], pid; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
153 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
154 // Make the pipes? |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
155 if (pipes) { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
156 if (pipe(cestnepasun) || pipe(cestnepasun+2)) perror_exit("pipe"); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
157 pipes[0] = cestnepasun[1]; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
158 pipes[1] = cestnepasun[2]; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
159 } |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
160 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
161 // Child process |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
162 if (!(pid = xfork())) { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
163 // Dance of the stdin/stdout redirection. |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
164 if (pipes) { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
165 close(cestnepasun[1]); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
166 close(cestnepasun[2]); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
167 // if we had no stdin/out, pipe handles could overlap, so test for that |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
168 if (cestnepasun[0]) { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
169 dup2(cestnepasun[0], 0); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
170 close(cestnepasun[0]); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
171 } |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
172 dup2(cestnepasun[3], 1); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
173 dup2(cestnepasun[3], 2); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
174 if (cestnepasun[3] > 2) close(cestnepasun[3]); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
175 } |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
176 if (argv) { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
177 if (CFG_TOYBOX) toy_exec(argv); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
178 execvp(argv[0], argv); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
179 _exit(127); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
180 } |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
181 return 0; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
182 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
183 // Parent process |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
184 } else { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
185 if (pipes) { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
186 close(cestnepasun[0]); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
187 close(cestnepasun[3]); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
188 } |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
189 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
190 return pid; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
191 } |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
192 } |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
193 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
194 int xpclose(pid_t pid, int *pipes) |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
195 { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
196 int rc = 127; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
197 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
198 if (pipes) { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
199 close(pipes[0]); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
200 close(pipes[1]); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
201 } |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
202 waitpid(pid, &rc, 0); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
203 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
204 return WIFEXITED(rc) ? WEXITSTATUS(rc) : WTERMSIG(rc) + 127; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
205 } |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1327
diff
changeset
|
206 |
951 | 207 void xaccess(char *path, int flags) |
208 { | |
209 if (access(path, flags)) perror_exit("Can't access '%s'", path); | |
210 } | |
211 | |
212 // Die unless we can delete a file. (File must exist to be deleted.) | |
213 void xunlink(char *path) | |
214 { | |
215 if (unlink(path)) perror_exit("unlink '%s'", path); | |
216 } | |
217 | |
218 // Die unless we can open/create a file, returning file descriptor. | |
219 int xcreate(char *path, int flags, int mode) | |
220 { | |
1403
411cf82cdf77
Default xcreate/xopen to O_CLOEXEC. (Pass O_CLOEXEC in the flags to switch it back off.)
Rob Landley <rob@landley.net>
parents:
1400
diff
changeset
|
221 int fd = open(path, flags^O_CLOEXEC, mode); |
951 | 222 if (fd == -1) perror_exit("%s", path); |
223 return fd; | |
224 } | |
225 | |
226 // Die unless we can open a file, returning file descriptor. | |
227 int xopen(char *path, int flags) | |
228 { | |
229 return xcreate(path, flags, 0); | |
230 } | |
231 | |
232 void xclose(int fd) | |
233 { | |
234 if (close(fd)) perror_exit("xclose"); | |
235 } | |
236 | |
237 int xdup(int fd) | |
238 { | |
239 if (fd != -1) { | |
240 fd = dup(fd); | |
241 if (fd == -1) perror_exit("xdup"); | |
242 } | |
243 return fd; | |
244 } | |
245 | |
991
252caf3d2b88
Forgot to check in xfdopen(). My bad.
Rob Landley <rob@landley.net>
parents:
956
diff
changeset
|
246 FILE *xfdopen(int fd, char *mode) |
252caf3d2b88
Forgot to check in xfdopen(). My bad.
Rob Landley <rob@landley.net>
parents:
956
diff
changeset
|
247 { |
252caf3d2b88
Forgot to check in xfdopen(). My bad.
Rob Landley <rob@landley.net>
parents:
956
diff
changeset
|
248 FILE *f = fdopen(fd, mode); |
252caf3d2b88
Forgot to check in xfdopen(). My bad.
Rob Landley <rob@landley.net>
parents:
956
diff
changeset
|
249 |
252caf3d2b88
Forgot to check in xfdopen(). My bad.
Rob Landley <rob@landley.net>
parents:
956
diff
changeset
|
250 if (!f) perror_exit("xfdopen"); |
252caf3d2b88
Forgot to check in xfdopen(). My bad.
Rob Landley <rob@landley.net>
parents:
956
diff
changeset
|
251 |
252caf3d2b88
Forgot to check in xfdopen(). My bad.
Rob Landley <rob@landley.net>
parents:
956
diff
changeset
|
252 return f; |
252caf3d2b88
Forgot to check in xfdopen(). My bad.
Rob Landley <rob@landley.net>
parents:
956
diff
changeset
|
253 } |
252caf3d2b88
Forgot to check in xfdopen(). My bad.
Rob Landley <rob@landley.net>
parents:
956
diff
changeset
|
254 |
951 | 255 // Die unless we can open/create a file, returning FILE *. |
256 FILE *xfopen(char *path, char *mode) | |
257 { | |
258 FILE *f = fopen(path, mode); | |
259 if (!f) perror_exit("No file %s", path); | |
260 return f; | |
261 } | |
262 | |
263 // Die if there's an error other than EOF. | |
264 size_t xread(int fd, void *buf, size_t len) | |
265 { | |
266 ssize_t ret = read(fd, buf, len); | |
267 if (ret < 0) perror_exit("xread"); | |
268 | |
269 return ret; | |
270 } | |
271 | |
272 void xreadall(int fd, void *buf, size_t len) | |
273 { | |
274 if (len != readall(fd, buf, len)) perror_exit("xreadall"); | |
275 } | |
276 | |
277 // There's no xwriteall(), just xwrite(). When we read, there may or may not | |
278 // be more data waiting. When we write, there is data and it had better go | |
279 // somewhere. | |
280 | |
281 void xwrite(int fd, void *buf, size_t len) | |
282 { | |
283 if (len != writeall(fd, buf, len)) perror_exit("xwrite"); | |
284 } | |
285 | |
286 // Die if lseek fails, probably due to being called on a pipe. | |
287 | |
288 off_t xlseek(int fd, off_t offset, int whence) | |
289 { | |
290 offset = lseek(fd, offset, whence); | |
291 if (offset<0) perror_exit("lseek"); | |
292 | |
293 return offset; | |
294 } | |
295 | |
296 char *xgetcwd(void) | |
297 { | |
298 char *buf = getcwd(NULL, 0); | |
299 if (!buf) perror_exit("xgetcwd"); | |
300 | |
301 return buf; | |
302 } | |
303 | |
304 void xstat(char *path, struct stat *st) | |
305 { | |
306 if(stat(path, st)) perror_exit("Can't stat %s", path); | |
307 } | |
308 | |
309 // Cannonicalize path, even to file with one or more missing components at end. | |
310 // if exact, require last path component to exist | |
311 char *xabspath(char *path, int exact) | |
312 { | |
313 struct string_list *todo, *done = 0; | |
314 int try = 9999, dirfd = open("/", 0);; | |
315 char buf[4096], *ret; | |
316 | |
317 // If this isn't an absolute path, start with cwd. | |
318 if (*path != '/') { | |
319 char *temp = xgetcwd(); | |
320 | |
321 splitpath(path, splitpath(temp, &todo)); | |
322 free(temp); | |
323 } else splitpath(path, &todo); | |
324 | |
325 // Iterate through path components | |
326 while (todo) { | |
327 struct string_list *new = llist_pop(&todo), **tail; | |
328 ssize_t len; | |
329 | |
330 if (!try--) { | |
331 errno = ELOOP; | |
332 goto error; | |
333 } | |
334 | |
335 // Removable path componenents. | |
336 if (!strcmp(new->str, ".") || !strcmp(new->str, "..")) { | |
337 int x = new->str[1]; | |
338 | |
339 free(new); | |
340 if (x) { | |
341 if (done) free(llist_pop(&done)); | |
342 len = 0; | |
343 } else continue; | |
344 | |
345 // Is this a symlink? | |
346 } else len=readlinkat(dirfd, new->str, buf, 4096); | |
347 | |
348 if (len>4095) goto error; | |
349 if (len<1) { | |
350 int fd; | |
351 char *s = ".."; | |
352 | |
353 // For .. just move dirfd | |
354 if (len) { | |
355 // Not a symlink: add to linked list, move dirfd, fail if error | |
356 if ((exact || todo) && errno != EINVAL) goto error; | |
357 new->next = done; | |
358 done = new; | |
359 if (errno == EINVAL && !todo) break; | |
360 s = new->str; | |
361 } | |
362 fd = openat(dirfd, s, 0); | |
363 if (fd == -1 && (exact || todo || errno != ENOENT)) goto error; | |
364 close(dirfd); | |
365 dirfd = fd; | |
366 continue; | |
367 } | |
368 | |
369 // If this symlink is to an absolute path, discard existing resolved path | |
370 buf[len] = 0; | |
371 if (*buf == '/') { | |
372 llist_traverse(done, free); | |
373 done=0; | |
374 close(dirfd); | |
375 dirfd = open("/", 0); | |
376 } | |
377 free(new); | |
378 | |
379 // prepend components of new path. Note symlink to "/" will leave new NULL | |
380 tail = splitpath(buf, &new); | |
381 | |
382 // symlink to "/" will return null and leave tail alone | |
383 if (new) { | |
384 *tail = todo; | |
385 todo = new; | |
386 } | |
387 } | |
388 close(dirfd); | |
389 | |
390 // At this point done has the path, in reverse order. Reverse list while | |
391 // calculating buffer length. | |
392 | |
393 try = 2; | |
394 while (done) { | |
395 struct string_list *temp = llist_pop(&done);; | |
396 | |
397 if (todo) try++; | |
398 try += strlen(temp->str); | |
399 temp->next = todo; | |
400 todo = temp; | |
401 } | |
402 | |
403 // Assemble return buffer | |
404 | |
405 ret = xmalloc(try); | |
406 *ret = '/'; | |
407 ret [try = 1] = 0; | |
408 while (todo) { | |
409 if (try>1) ret[try++] = '/'; | |
410 try = stpcpy(ret+try, todo->str) - ret; | |
411 free(llist_pop(&todo)); | |
412 } | |
413 | |
414 return ret; | |
415 | |
416 error: | |
417 close(dirfd); | |
418 llist_traverse(todo, free); | |
419 llist_traverse(done, free); | |
420 | |
421 return NULL; | |
422 } | |
423 | |
424 void xchdir(char *path) | |
425 { | |
426 if (chdir(path)) error_exit("chdir '%s'", path); | |
427 } | |
428 | |
1156
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
429 void xchroot(char *path) |
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
430 { |
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
431 if (chroot(path)) error_exit("chroot '%s'", path); |
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
432 xchdir("/"); |
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
433 } |
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
434 |
1129
c644f85444d0
Move xgetpwuid() and xgetgrgid() into xwrap.c
Rob Landley <rob@landley.net>
parents:
1105
diff
changeset
|
435 struct passwd *xgetpwuid(uid_t uid) |
c644f85444d0
Move xgetpwuid() and xgetgrgid() into xwrap.c
Rob Landley <rob@landley.net>
parents:
1105
diff
changeset
|
436 { |
c644f85444d0
Move xgetpwuid() and xgetgrgid() into xwrap.c
Rob Landley <rob@landley.net>
parents:
1105
diff
changeset
|
437 struct passwd *pwd = getpwuid(uid); |
1130
6df194c6de88
Add xgetpwnam() to lib/xwrap.c.
Rob Landley <rob@landley.net>
parents:
1129
diff
changeset
|
438 if (!pwd) error_exit("bad uid %ld", (long)uid); |
1129
c644f85444d0
Move xgetpwuid() and xgetgrgid() into xwrap.c
Rob Landley <rob@landley.net>
parents:
1105
diff
changeset
|
439 return pwd; |
c644f85444d0
Move xgetpwuid() and xgetgrgid() into xwrap.c
Rob Landley <rob@landley.net>
parents:
1105
diff
changeset
|
440 } |
c644f85444d0
Move xgetpwuid() and xgetgrgid() into xwrap.c
Rob Landley <rob@landley.net>
parents:
1105
diff
changeset
|
441 |
c644f85444d0
Move xgetpwuid() and xgetgrgid() into xwrap.c
Rob Landley <rob@landley.net>
parents:
1105
diff
changeset
|
442 struct group *xgetgrgid(gid_t gid) |
c644f85444d0
Move xgetpwuid() and xgetgrgid() into xwrap.c
Rob Landley <rob@landley.net>
parents:
1105
diff
changeset
|
443 { |
c644f85444d0
Move xgetpwuid() and xgetgrgid() into xwrap.c
Rob Landley <rob@landley.net>
parents:
1105
diff
changeset
|
444 struct group *group = getgrgid(gid); |
1400
31cb9ba1815c
Improve gid/uid error messages.
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
445 |
31cb9ba1815c
Improve gid/uid error messages.
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
446 if (!group) perror_exit("gid %ld", (long)gid); |
1129
c644f85444d0
Move xgetpwuid() and xgetgrgid() into xwrap.c
Rob Landley <rob@landley.net>
parents:
1105
diff
changeset
|
447 return group; |
c644f85444d0
Move xgetpwuid() and xgetgrgid() into xwrap.c
Rob Landley <rob@landley.net>
parents:
1105
diff
changeset
|
448 } |
c644f85444d0
Move xgetpwuid() and xgetgrgid() into xwrap.c
Rob Landley <rob@landley.net>
parents:
1105
diff
changeset
|
449 |
1130
6df194c6de88
Add xgetpwnam() to lib/xwrap.c.
Rob Landley <rob@landley.net>
parents:
1129
diff
changeset
|
450 struct passwd *xgetpwnam(char *name) |
6df194c6de88
Add xgetpwnam() to lib/xwrap.c.
Rob Landley <rob@landley.net>
parents:
1129
diff
changeset
|
451 { |
6df194c6de88
Add xgetpwnam() to lib/xwrap.c.
Rob Landley <rob@landley.net>
parents:
1129
diff
changeset
|
452 struct passwd *up = getpwnam(name); |
1400
31cb9ba1815c
Improve gid/uid error messages.
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
453 |
31cb9ba1815c
Improve gid/uid error messages.
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
454 if (!up) perror_exit("user '%s'", name); |
1130
6df194c6de88
Add xgetpwnam() to lib/xwrap.c.
Rob Landley <rob@landley.net>
parents:
1129
diff
changeset
|
455 return up; |
6df194c6de88
Add xgetpwnam() to lib/xwrap.c.
Rob Landley <rob@landley.net>
parents:
1129
diff
changeset
|
456 } |
6df194c6de88
Add xgetpwnam() to lib/xwrap.c.
Rob Landley <rob@landley.net>
parents:
1129
diff
changeset
|
457 |
1420
9d760c092c41
Implement exec -user, -group, and -newer. Enable find in defconfig.
Rob Landley <rob@landley.net>
parents:
1408
diff
changeset
|
458 struct group *xgetgrnam(char *name) |
9d760c092c41
Implement exec -user, -group, and -newer. Enable find in defconfig.
Rob Landley <rob@landley.net>
parents:
1408
diff
changeset
|
459 { |
9d760c092c41
Implement exec -user, -group, and -newer. Enable find in defconfig.
Rob Landley <rob@landley.net>
parents:
1408
diff
changeset
|
460 struct group *gr = getgrnam(name); |
9d760c092c41
Implement exec -user, -group, and -newer. Enable find in defconfig.
Rob Landley <rob@landley.net>
parents:
1408
diff
changeset
|
461 |
9d760c092c41
Implement exec -user, -group, and -newer. Enable find in defconfig.
Rob Landley <rob@landley.net>
parents:
1408
diff
changeset
|
462 if (!gr) perror_exit("group '%s'", name); |
9d760c092c41
Implement exec -user, -group, and -newer. Enable find in defconfig.
Rob Landley <rob@landley.net>
parents:
1408
diff
changeset
|
463 return gr; |
9d760c092c41
Implement exec -user, -group, and -newer. Enable find in defconfig.
Rob Landley <rob@landley.net>
parents:
1408
diff
changeset
|
464 } |
9d760c092c41
Implement exec -user, -group, and -newer. Enable find in defconfig.
Rob Landley <rob@landley.net>
parents:
1408
diff
changeset
|
465 |
1156
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
466 // setuid() can fail (for example, too many processes belonging to that user), |
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
467 // which opens a security hole if the process continues as the original user. |
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
468 |
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
469 void xsetuser(struct passwd *pwd) |
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
470 { |
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
471 if (initgroups(pwd->pw_name, pwd->pw_gid) || setgid(pwd->pw_uid) |
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
472 || setuid(pwd->pw_uid)) perror_exit("xsetuser '%s'", pwd->pw_name); |
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
473 } |
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
1130
diff
changeset
|
474 |
951 | 475 // This can return null (meaning file not found). It just won't return null |
476 // for memory allocation reasons. | |
477 char *xreadlink(char *name) | |
478 { | |
479 int len, size = 0; | |
480 char *buf = 0; | |
481 | |
482 // Grow by 64 byte chunks until it's big enough. | |
483 for(;;) { | |
484 size +=64; | |
485 buf = xrealloc(buf, size); | |
486 len = readlink(name, buf, size); | |
487 | |
488 if (len<0) { | |
489 free(buf); | |
490 return 0; | |
491 } | |
492 if (len<size) { | |
493 buf[len]=0; | |
494 return buf; | |
495 } | |
496 } | |
497 } | |
498 | |
1170
8afe1fde9314
Pass through all the readfile() arguments from xreadfile().
Rob Landley <rob@landley.net>
parents:
1156
diff
changeset
|
499 char *xreadfile(char *name, char *buf, off_t len) |
951 | 500 { |
1170
8afe1fde9314
Pass through all the readfile() arguments from xreadfile().
Rob Landley <rob@landley.net>
parents:
1156
diff
changeset
|
501 if (!(buf = readfile(name, buf, len))) perror_exit("Bad '%s'", name); |
8afe1fde9314
Pass through all the readfile() arguments from xreadfile().
Rob Landley <rob@landley.net>
parents:
1156
diff
changeset
|
502 |
951 | 503 return buf; |
504 } | |
505 | |
506 int xioctl(int fd, int request, void *data) | |
507 { | |
508 int rc; | |
509 | |
510 errno = 0; | |
511 rc = ioctl(fd, request, data); | |
512 if (rc == -1 && errno) perror_exit("ioctl %x", request); | |
513 | |
514 return rc; | |
515 } | |
516 | |
517 // Open a /var/run/NAME.pid file, dying if we can't write it or if it currently | |
518 // exists and is this executable. | |
519 void xpidfile(char *name) | |
520 { | |
521 char pidfile[256], spid[32]; | |
522 int i, fd; | |
523 pid_t pid; | |
524 | |
525 sprintf(pidfile, "/var/run/%s.pid", name); | |
526 // Try three times to open the sucker. | |
527 for (i=0; i<3; i++) { | |
1028 | 528 fd = open(pidfile, O_CREAT|O_EXCL|O_WRONLY, 0644); |
951 | 529 if (fd != -1) break; |
530 | |
531 // If it already existed, read it. Loop for race condition. | |
532 fd = open(pidfile, O_RDONLY); | |
533 if (fd == -1) continue; | |
534 | |
535 // Is the old program still there? | |
536 spid[xread(fd, spid, sizeof(spid)-1)] = 0; | |
537 close(fd); | |
538 pid = atoi(spid); | |
1053
501fd74c028e
Fix for xpidfile spotted by Felix Janda.
Rob Landley <rob@landley.net>
parents:
1043
diff
changeset
|
539 if (pid < 1 || (kill(pid, 0) && errno == ESRCH)) unlink(pidfile); |
951 | 540 |
541 // An else with more sanity checking might be nice here. | |
542 } | |
543 | |
544 if (i == 3) error_exit("xpidfile %s", name); | |
545 | |
546 xwrite(fd, spid, sprintf(spid, "%ld\n", (long)getpid())); | |
547 close(fd); | |
548 } | |
549 | |
550 // Copy the rest of in to out and close both files. | |
551 | |
552 void xsendfile(int in, int out) | |
553 { | |
554 long len; | |
555 char buf[4096]; | |
556 | |
557 if (in<0) return; | |
558 for (;;) { | |
559 len = xread(in, buf, 4096); | |
560 if (len<1) break; | |
561 xwrite(out, buf, len); | |
562 } | |
563 } | |
952
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
564 |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
565 // parse fractional seconds with optional s/m/h/d suffix |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
566 long xparsetime(char *arg, long units, long *fraction) |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
567 { |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
568 double d; |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
569 long l; |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
570 |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
571 if (CFG_TOYBOX_FLOAT) d = strtod(arg, &arg); |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
572 else l = strtoul(arg, &arg, 10); |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
573 |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
574 // Parse suffix |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
575 if (*arg) { |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
576 int ismhd[]={1,60,3600,86400}, i = stridx("smhd", *arg); |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
577 |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
578 if (i == -1) error_exit("Unknown suffix '%c'", *arg); |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
579 if (CFG_TOYBOX_FLOAT) d *= ismhd[i]; |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
580 else l *= ismhd[i]; |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
581 } |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
582 |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
583 if (CFG_TOYBOX_FLOAT) { |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
584 l = (long)d; |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
585 if (fraction) *fraction = units*(d-l); |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
586 } else if (fraction) *fraction = 0; |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
587 |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
588 return l; |
ce0519f6457c
Add timeout, factoring out common code from sleep.
Rob Landley <rob@landley.net>
parents:
951
diff
changeset
|
589 } |
1235
63db77909fc8
Group headers by standard (POSIX or LSB) or function (internationalization, networking). Move headers standards ignore (but which have been there >15 years) to lib/portability.h. Fold xregcomp into lib since it's posix.
Rob Landley <rob@landley.net>
parents:
1219
diff
changeset
|
590 |
63db77909fc8
Group headers by standard (POSIX or LSB) or function (internationalization, networking). Move headers standards ignore (but which have been there >15 years) to lib/portability.h. Fold xregcomp into lib since it's posix.
Rob Landley <rob@landley.net>
parents:
1219
diff
changeset
|
591 // Compile a regular expression into a regex_t |
63db77909fc8
Group headers by standard (POSIX or LSB) or function (internationalization, networking). Move headers standards ignore (but which have been there >15 years) to lib/portability.h. Fold xregcomp into lib since it's posix.
Rob Landley <rob@landley.net>
parents:
1219
diff
changeset
|
592 void xregcomp(regex_t *preg, char *regex, int cflags) |
63db77909fc8
Group headers by standard (POSIX or LSB) or function (internationalization, networking). Move headers standards ignore (but which have been there >15 years) to lib/portability.h. Fold xregcomp into lib since it's posix.
Rob Landley <rob@landley.net>
parents:
1219
diff
changeset
|
593 { |
63db77909fc8
Group headers by standard (POSIX or LSB) or function (internationalization, networking). Move headers standards ignore (but which have been there >15 years) to lib/portability.h. Fold xregcomp into lib since it's posix.
Rob Landley <rob@landley.net>
parents:
1219
diff
changeset
|
594 int rc = regcomp(preg, regex, cflags); |
63db77909fc8
Group headers by standard (POSIX or LSB) or function (internationalization, networking). Move headers standards ignore (but which have been there >15 years) to lib/portability.h. Fold xregcomp into lib since it's posix.
Rob Landley <rob@landley.net>
parents:
1219
diff
changeset
|
595 |
63db77909fc8
Group headers by standard (POSIX or LSB) or function (internationalization, networking). Move headers standards ignore (but which have been there >15 years) to lib/portability.h. Fold xregcomp into lib since it's posix.
Rob Landley <rob@landley.net>
parents:
1219
diff
changeset
|
596 if (rc) { |
63db77909fc8
Group headers by standard (POSIX or LSB) or function (internationalization, networking). Move headers standards ignore (but which have been there >15 years) to lib/portability.h. Fold xregcomp into lib since it's posix.
Rob Landley <rob@landley.net>
parents:
1219
diff
changeset
|
597 regerror(rc, preg, libbuf, sizeof(libbuf)); |
63db77909fc8
Group headers by standard (POSIX or LSB) or function (internationalization, networking). Move headers standards ignore (but which have been there >15 years) to lib/portability.h. Fold xregcomp into lib since it's posix.
Rob Landley <rob@landley.net>
parents:
1219
diff
changeset
|
598 error_exit("xregcomp: %s", libbuf); |
63db77909fc8
Group headers by standard (POSIX or LSB) or function (internationalization, networking). Move headers standards ignore (but which have been there >15 years) to lib/portability.h. Fold xregcomp into lib since it's posix.
Rob Landley <rob@landley.net>
parents:
1219
diff
changeset
|
599 } |
63db77909fc8
Group headers by standard (POSIX or LSB) or function (internationalization, networking). Move headers standards ignore (but which have been there >15 years) to lib/portability.h. Fold xregcomp into lib since it's posix.
Rob Landley <rob@landley.net>
parents:
1219
diff
changeset
|
600 } |