aboutsummaryrefslogtreecommitdiff
path: root/libbb/xfuncs.c
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-10-05 10:17:08 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-10-05 10:17:08 +0000
commitc2a198d4d1552b349750a13d2c22486e99ef6270 (patch)
tree20db60b3a787cd3152160fb60206922fd5eb18ed /libbb/xfuncs.c
parentd8cf793135eac928e653eb5178894a611aa27837 (diff)
downloadbusybox-w32-c2a198d4d1552b349750a13d2c22486e99ef6270.tar.gz
busybox-w32-c2a198d4d1552b349750a13d2c22486e99ef6270.tar.bz2
busybox-w32-c2a198d4d1552b349750a13d2c22486e99ef6270.zip
build system overhaul
git-svn-id: svn://busybox.net/trunk/busybox@16307 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb/xfuncs.c')
-rw-r--r--libbb/xfuncs.c67
1 files changed, 0 insertions, 67 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index f1d4486c3..de765a32d 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -20,7 +20,6 @@
20 * Since dmalloc's prototypes overwrite the impls here as they are 20 * Since dmalloc's prototypes overwrite the impls here as they are
21 * included after these prototypes in libbb.h, all is well. 21 * included after these prototypes in libbb.h, all is well.
22 */ 22 */
23#ifdef L_xmalloc
24// Die if we can't allocate size bytes of memory. 23// Die if we can't allocate size bytes of memory.
25void *xmalloc(size_t size) 24void *xmalloc(size_t size)
26{ 25{
@@ -29,9 +28,7 @@ void *xmalloc(size_t size)
29 bb_error_msg_and_die(bb_msg_memory_exhausted); 28 bb_error_msg_and_die(bb_msg_memory_exhausted);
30 return ptr; 29 return ptr;
31} 30}
32#endif
33 31
34#ifdef L_xrealloc
35// Die if we can't resize previously allocated memory. (This returns a pointer 32// Die if we can't resize previously allocated memory. (This returns a pointer
36// to the new memory, which may or may not be the same as the old memory. 33// to the new memory, which may or may not be the same as the old memory.
37// It'll copy the contents to a new chunk and free the old one if necessary.) 34// It'll copy the contents to a new chunk and free the old one if necessary.)
@@ -42,11 +39,8 @@ void *xrealloc(void *ptr, size_t size)
42 bb_error_msg_and_die(bb_msg_memory_exhausted); 39 bb_error_msg_and_die(bb_msg_memory_exhausted);
43 return ptr; 40 return ptr;
44} 41}
45#endif
46#endif /* DMALLOC */ 42#endif /* DMALLOC */
47 43
48
49#ifdef L_xzalloc
50// Die if we can't allocate and zero size bytes of memory. 44// Die if we can't allocate and zero size bytes of memory.
51void *xzalloc(size_t size) 45void *xzalloc(size_t size)
52{ 46{
@@ -54,9 +48,7 @@ void *xzalloc(size_t size)
54 memset(ptr, 0, size); 48 memset(ptr, 0, size);
55 return ptr; 49 return ptr;
56} 50}
57#endif
58 51
59#ifdef L_xstrdup
60// Die if we can't copy a string to freshly allocated memory. 52// Die if we can't copy a string to freshly allocated memory.
61char * xstrdup(const char *s) 53char * xstrdup(const char *s)
62{ 54{
@@ -72,9 +64,7 @@ char * xstrdup(const char *s)
72 64
73 return t; 65 return t;
74} 66}
75#endif
76 67
77#ifdef L_xstrndup
78// Die if we can't allocate n+1 bytes (space for the null terminator) and copy 68// Die if we can't allocate n+1 bytes (space for the null terminator) and copy
79// the (possibly truncated to length n) string into it. 69// the (possibly truncated to length n) string into it.
80char * xstrndup(const char *s, int n) 70char * xstrndup(const char *s, int n)
@@ -88,9 +78,7 @@ char * xstrndup(const char *s, int n)
88 78
89 return safe_strncpy(t,s,n); 79 return safe_strncpy(t,s,n);
90} 80}
91#endif
92 81
93#ifdef L_xfopen
94// Die if we can't open a file and return a FILE * to it. 82// Die if we can't open a file and return a FILE * to it.
95// Notice we haven't got xfread(), This is for use with fscanf() and friends. 83// Notice we haven't got xfread(), This is for use with fscanf() and friends.
96FILE *xfopen(const char *path, const char *mode) 84FILE *xfopen(const char *path, const char *mode)
@@ -100,9 +88,7 @@ FILE *xfopen(const char *path, const char *mode)
100 bb_perror_msg_and_die("%s", path); 88 bb_perror_msg_and_die("%s", path);
101 return fp; 89 return fp;
102} 90}
103#endif
104 91
105#ifdef L_xopen
106// Die if we can't open an existing file and return an fd. 92// Die if we can't open an existing file and return an fd.
107int xopen(const char *pathname, int flags) 93int xopen(const char *pathname, int flags)
108{ 94{
@@ -111,9 +97,7 @@ int xopen(const char *pathname, int flags)
111 97
112 return xopen3(pathname, flags, 0777); 98 return xopen3(pathname, flags, 0777);
113} 99}
114#endif
115 100
116#ifdef L_xopen3
117// Die if we can't open a new file and return an fd. 101// Die if we can't open a new file and return an fd.
118int xopen3(const char *pathname, int flags, int mode) 102int xopen3(const char *pathname, int flags, int mode)
119{ 103{
@@ -125,9 +109,7 @@ int xopen3(const char *pathname, int flags, int mode)
125 } 109 }
126 return ret; 110 return ret;
127} 111}
128#endif
129 112
130#ifdef L_xread
131// Die with an error message if we can't read the entire buffer. 113// Die with an error message if we can't read the entire buffer.
132void xread(int fd, void *buf, size_t count) 114void xread(int fd, void *buf, size_t count)
133{ 115{
@@ -140,9 +122,7 @@ void xread(int fd, void *buf, size_t count)
140 buf = ((char *) buf) + size; 122 buf = ((char *) buf) + size;
141 } 123 }
142} 124}
143#endif
144 125
145#ifdef L_xwrite
146// Die with an error message if we can't write the entire buffer. 126// Die with an error message if we can't write the entire buffer.
147void xwrite(int fd, void *buf, size_t count) 127void xwrite(int fd, void *buf, size_t count)
148{ 128{
@@ -155,17 +135,13 @@ void xwrite(int fd, void *buf, size_t count)
155 buf = ((char *) buf) + size; 135 buf = ((char *) buf) + size;
156 } 136 }
157} 137}
158#endif
159 138
160#ifdef L_xlseek
161// Die with an error message if we can't lseek to the right spot. 139// Die with an error message if we can't lseek to the right spot.
162void xlseek(int fd, off_t offset, int whence) 140void xlseek(int fd, off_t offset, int whence)
163{ 141{
164 if (offset != lseek(fd, offset, whence)) bb_error_msg_and_die("lseek"); 142 if (offset != lseek(fd, offset, whence)) bb_error_msg_and_die("lseek");
165} 143}
166#endif
167 144
168#ifdef L_xread_char
169// Die with an error message if we can't read one character. 145// Die with an error message if we can't read one character.
170unsigned char xread_char(int fd) 146unsigned char xread_char(int fd)
171{ 147{
@@ -175,9 +151,7 @@ unsigned char xread_char(int fd)
175 151
176 return(tmp); 152 return(tmp);
177} 153}
178#endif
179 154
180#ifdef L_xferror
181// Die with supplied error message if this FILE * has ferror set. 155// Die with supplied error message if this FILE * has ferror set.
182void xferror(FILE *fp, const char *fn) 156void xferror(FILE *fp, const char *fn)
183{ 157{
@@ -185,17 +159,13 @@ void xferror(FILE *fp, const char *fn)
185 bb_error_msg_and_die("%s", fn); 159 bb_error_msg_and_die("%s", fn);
186 } 160 }
187} 161}
188#endif
189 162
190#ifdef L_xferror_stdout
191// Die with an error message if stdout has ferror set. 163// Die with an error message if stdout has ferror set.
192void xferror_stdout(void) 164void xferror_stdout(void)
193{ 165{
194 xferror(stdout, bb_msg_standard_output); 166 xferror(stdout, bb_msg_standard_output);
195} 167}
196#endif
197 168
198#ifdef L_xfflush_stdout
199// Die with an error message if we have trouble flushing stdout. 169// Die with an error message if we have trouble flushing stdout.
200void xfflush_stdout(void) 170void xfflush_stdout(void)
201{ 171{
@@ -203,9 +173,7 @@ void xfflush_stdout(void)
203 bb_perror_msg_and_die(bb_msg_standard_output); 173 bb_perror_msg_and_die(bb_msg_standard_output);
204 } 174 }
205} 175}
206#endif
207 176
208#ifdef L_spawn
209// This does a fork/exec in one call, using vfork(). Return PID of new child, 177// This does a fork/exec in one call, using vfork(). Return PID of new child,
210// -1 for failure. Runs argv[0], searching path if that has no / in it. 178// -1 for failure. Runs argv[0], searching path if that has no / in it.
211pid_t spawn(char **argv) 179pid_t spawn(char **argv)
@@ -230,9 +198,7 @@ pid_t spawn(char **argv)
230 } 198 }
231 return failed ? failed : pid; 199 return failed ? failed : pid;
232} 200}
233#endif
234 201
235#ifdef L_xspawn
236// Die with an error message if we can't spawn a child process. 202// Die with an error message if we can't spawn a child process.
237pid_t xspawn(char **argv) 203pid_t xspawn(char **argv)
238{ 204{
@@ -240,9 +206,7 @@ pid_t xspawn(char **argv)
240 if (pid < 0) bb_perror_msg_and_die("%s", *argv); 206 if (pid < 0) bb_perror_msg_and_die("%s", *argv);
241 return pid; 207 return pid;
242} 208}
243#endif
244 209
245#ifdef L_wait4
246// Wait for the specified child PID to exit, returning child's error return. 210// Wait for the specified child PID to exit, returning child's error return.
247int wait4pid(int pid) 211int wait4pid(int pid)
248{ 212{
@@ -253,17 +217,13 @@ int wait4pid(int pid)
253 if (WIFSIGNALED(status)) return WTERMSIG(status); 217 if (WIFSIGNALED(status)) return WTERMSIG(status);
254 return 0; 218 return 0;
255} 219}
256#endif
257 220
258#ifdef L_xsetenv
259void xsetenv(const char *key, const char *value) 221void xsetenv(const char *key, const char *value)
260{ 222{
261 if(setenv(key, value, 1)) 223 if(setenv(key, value, 1))
262 bb_error_msg_and_die(bb_msg_memory_exhausted); 224 bb_error_msg_and_die(bb_msg_memory_exhausted);
263} 225}
264#endif
265 226
266#ifdef L_itoa
267// Convert unsigned integer to ascii, writing into supplied buffer. A 227// Convert unsigned integer to ascii, writing into supplied buffer. A
268// truncated result is always null terminated (unless buflen is 0), and 228// truncated result is always null terminated (unless buflen is 0), and
269// contains the first few digits of the result ala strncpy. 229// contains the first few digits of the result ala strncpy.
@@ -319,9 +279,7 @@ char *itoa(int n)
319 279
320 return local_buf; 280 return local_buf;
321} 281}
322#endif
323 282
324#ifdef L_setuid
325// Die with an error message if we can't set gid. (Because resource limits may 283// Die with an error message if we can't set gid. (Because resource limits may
326// limit this user to a given number of processes, and if that fills up the 284// limit this user to a given number of processes, and if that fills up the
327// setgid() will fail and we'll _still_be_root_, which is bad.) 285// setgid() will fail and we'll _still_be_root_, which is bad.)
@@ -335,9 +293,7 @@ void xsetuid(uid_t uid)
335{ 293{
336 if (setuid(uid)) bb_error_msg_and_die("setuid"); 294 if (setuid(uid)) bb_error_msg_and_die("setuid");
337} 295}
338#endif
339 296
340#ifdef L_fdlength
341// Return how long the file at fd is, if there's any way to determine it. 297// Return how long the file at fd is, if there's any way to determine it.
342off_t fdlength(int fd) 298off_t fdlength(int fd)
343{ 299{
@@ -375,9 +331,7 @@ off_t fdlength(int fd)
375 331
376 return pos + 1; 332 return pos + 1;
377} 333}
378#endif
379 334
380#ifdef L_xasprintf
381// Die with an error message if we can't malloc() enough space and do an 335// Die with an error message if we can't malloc() enough space and do an
382// sprintf() into that space. 336// sprintf() into that space.
383char *xasprintf(const char *format, ...) 337char *xasprintf(const char *format, ...)
@@ -405,9 +359,7 @@ char *xasprintf(const char *format, ...)
405 if (r < 0) bb_error_msg_and_die(bb_msg_memory_exhausted); 359 if (r < 0) bb_error_msg_and_die(bb_msg_memory_exhausted);
406 return string_ptr; 360 return string_ptr;
407} 361}
408#endif
409 362
410#ifdef L_xprint_and_close_file
411// Die with an error message if we can't copy an entire FILE * to stdout, then 363// Die with an error message if we can't copy an entire FILE * to stdout, then
412// close that file. 364// close that file.
413void xprint_and_close_file(FILE *file) 365void xprint_and_close_file(FILE *file)
@@ -418,18 +370,14 @@ void xprint_and_close_file(FILE *file)
418 370
419 fclose(file); 371 fclose(file);
420} 372}
421#endif
422 373
423#ifdef L_xchdir
424// Die if we can't chdir to a new path. 374// Die if we can't chdir to a new path.
425void xchdir(const char *path) 375void xchdir(const char *path)
426{ 376{
427 if (chdir(path)) 377 if (chdir(path))
428 bb_perror_msg_and_die("chdir(%s)", path); 378 bb_perror_msg_and_die("chdir(%s)", path);
429} 379}
430#endif
431 380
432#ifdef L_warn_opendir
433// Print a warning message if opendir() fails, but don't die. 381// Print a warning message if opendir() fails, but don't die.
434DIR *warn_opendir(const char *path) 382DIR *warn_opendir(const char *path)
435{ 383{
@@ -441,9 +389,7 @@ DIR *warn_opendir(const char *path)
441 } 389 }
442 return dp; 390 return dp;
443} 391}
444#endif
445 392
446#ifdef L_xopendir
447// Die with an error message if opendir() fails. 393// Die with an error message if opendir() fails.
448DIR *xopendir(const char *path) 394DIR *xopendir(const char *path)
449{ 395{
@@ -453,9 +399,7 @@ DIR *xopendir(const char *path)
453 bb_perror_msg_and_die("unable to open `%s'", path); 399 bb_perror_msg_and_die("unable to open `%s'", path);
454 return dp; 400 return dp;
455} 401}
456#endif
457 402
458#ifdef L_xdaemon
459#ifndef BB_NOMMU 403#ifndef BB_NOMMU
460// Die with an error message if we can't daemonize. 404// Die with an error message if we can't daemonize.
461void xdaemon(int nochdir, int noclose) 405void xdaemon(int nochdir, int noclose)
@@ -463,9 +407,7 @@ void xdaemon(int nochdir, int noclose)
463 if (daemon(nochdir, noclose)) bb_perror_msg_and_die("daemon"); 407 if (daemon(nochdir, noclose)) bb_perror_msg_and_die("daemon");
464} 408}
465#endif 409#endif
466#endif
467 410
468#ifdef L_xsocket
469// Die with an error message if we can't open a new socket. 411// Die with an error message if we can't open a new socket.
470int xsocket(int domain, int type, int protocol) 412int xsocket(int domain, int type, int protocol)
471{ 413{
@@ -475,34 +417,26 @@ int xsocket(int domain, int type, int protocol)
475 417
476 return r; 418 return r;
477} 419}
478#endif
479 420
480#ifdef L_xbind
481// Die with an error message if we can't bind a socket to an address. 421// Die with an error message if we can't bind a socket to an address.
482void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) 422void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen)
483{ 423{
484 if (bind(sockfd, my_addr, addrlen)) bb_perror_msg_and_die("bind"); 424 if (bind(sockfd, my_addr, addrlen)) bb_perror_msg_and_die("bind");
485} 425}
486#endif
487 426
488#ifdef L_xlisten
489// Die with an error message if we can't listen for connections on a socket. 427// Die with an error message if we can't listen for connections on a socket.
490void xlisten(int s, int backlog) 428void xlisten(int s, int backlog)
491{ 429{
492 if (listen(s, backlog)) bb_perror_msg_and_die("listen"); 430 if (listen(s, backlog)) bb_perror_msg_and_die("listen");
493} 431}
494#endif
495 432
496#ifdef L_xstat
497// xstat() - a stat() which dies on failure with meaningful error message 433// xstat() - a stat() which dies on failure with meaningful error message
498void xstat(char *name, struct stat *stat_buf) 434void xstat(char *name, struct stat *stat_buf)
499{ 435{
500 if (stat(name, stat_buf)) 436 if (stat(name, stat_buf))
501 bb_perror_msg_and_die("can't stat '%s'", name); 437 bb_perror_msg_and_die("can't stat '%s'", name);
502} 438}
503#endif
504 439
505#ifdef L_get_terminal_width_height
506/* It is perfectly ok to pass in a NULL for either width or for 440/* It is perfectly ok to pass in a NULL for either width or for
507 * * height, in which case that value will not be set. */ 441 * * height, in which case that value will not be set. */
508int get_terminal_width_height(int fd, int *width, int *height) 442int get_terminal_width_height(int fd, int *width, int *height)
@@ -524,4 +458,3 @@ int get_terminal_width_height(int fd, int *width, int *height)
524 458
525 return ret; 459 return ret;
526} 460}
527#endif