aboutsummaryrefslogtreecommitdiff
path: root/libbb/xfuncs_printf.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-06-27 02:52:20 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-06-27 02:52:20 +0000
commitdefc1ea34074e7882724c460260d307cdf981a70 (patch)
treefca9b9a5fe243f9c0c76b84824ea2ff92ea8e589 /libbb/xfuncs_printf.c
parent26bc57d8b26425f23f4be974cce7bf35c95c9a1a (diff)
downloadbusybox-w32-defc1ea34074e7882724c460260d307cdf981a70.tar.gz
busybox-w32-defc1ea34074e7882724c460260d307cdf981a70.tar.bz2
busybox-w32-defc1ea34074e7882724c460260d307cdf981a70.zip
*: introduce and use FAST_FUNC: regparm on i386, otherwise no-on
text data bss dec hex filename 808035 611 6868 815514 c719a busybox_old 804472 611 6868 811951 c63af busybox_unstripped
Diffstat (limited to 'libbb/xfuncs_printf.c')
-rw-r--r--libbb/xfuncs_printf.c96
1 files changed, 48 insertions, 48 deletions
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index 105939b5e..108e14043 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -33,7 +33,7 @@
33 * included after these prototypes in libbb.h, all is well. 33 * included after these prototypes in libbb.h, all is well.
34 */ 34 */
35// Warn if we can't allocate size bytes of memory. 35// Warn if we can't allocate size bytes of memory.
36void *malloc_or_warn(size_t size) 36void* FAST_FUNC malloc_or_warn(size_t size)
37{ 37{
38 void *ptr = malloc(size); 38 void *ptr = malloc(size);
39 if (ptr == NULL && size != 0) 39 if (ptr == NULL && size != 0)
@@ -42,7 +42,7 @@ void *malloc_or_warn(size_t size)
42} 42}
43 43
44// Die if we can't allocate size bytes of memory. 44// Die if we can't allocate size bytes of memory.
45void *xmalloc(size_t size) 45void* FAST_FUNC xmalloc(size_t size)
46{ 46{
47 void *ptr = malloc(size); 47 void *ptr = malloc(size);
48 if (ptr == NULL && size != 0) 48 if (ptr == NULL && size != 0)
@@ -53,7 +53,7 @@ void *xmalloc(size_t size)
53// Die if we can't resize previously allocated memory. (This returns a pointer 53// Die if we can't resize previously allocated memory. (This returns a pointer
54// to the new memory, which may or may not be the same as the old memory. 54// to the new memory, which may or may not be the same as the old memory.
55// It'll copy the contents to a new chunk and free the old one if necessary.) 55// It'll copy the contents to a new chunk and free the old one if necessary.)
56void *xrealloc(void *ptr, size_t size) 56void* FAST_FUNC xrealloc(void *ptr, size_t size)
57{ 57{
58 ptr = realloc(ptr, size); 58 ptr = realloc(ptr, size);
59 if (ptr == NULL && size != 0) 59 if (ptr == NULL && size != 0)
@@ -63,7 +63,7 @@ void *xrealloc(void *ptr, size_t size)
63#endif /* DMALLOC */ 63#endif /* DMALLOC */
64 64
65// Die if we can't allocate and zero size bytes of memory. 65// Die if we can't allocate and zero size bytes of memory.
66void *xzalloc(size_t size) 66void* FAST_FUNC xzalloc(size_t size)
67{ 67{
68 void *ptr = xmalloc(size); 68 void *ptr = xmalloc(size);
69 memset(ptr, 0, size); 69 memset(ptr, 0, size);
@@ -71,7 +71,7 @@ void *xzalloc(size_t size)
71} 71}
72 72
73// Die if we can't copy a string to freshly allocated memory. 73// Die if we can't copy a string to freshly allocated memory.
74char * xstrdup(const char *s) 74char* FAST_FUNC xstrdup(const char *s)
75{ 75{
76 char *t; 76 char *t;
77 77
@@ -88,7 +88,7 @@ char * xstrdup(const char *s)
88 88
89// Die if we can't allocate n+1 bytes (space for the null terminator) and copy 89// Die if we can't allocate n+1 bytes (space for the null terminator) and copy
90// the (possibly truncated to length n) string into it. 90// the (possibly truncated to length n) string into it.
91char *xstrndup(const char *s, int n) 91char* FAST_FUNC xstrndup(const char *s, int n)
92{ 92{
93 int m; 93 int m;
94 char *t; 94 char *t;
@@ -112,9 +112,9 @@ char *xstrndup(const char *s, int n)
112 return memcpy(t, s, n); 112 return memcpy(t, s, n);
113} 113}
114 114
115// Die if we can't open a file and return a FILE * to it. 115// Die if we can't open a file and return a FILE* to it.
116// Notice we haven't got xfread(), This is for use with fscanf() and friends. 116// Notice we haven't got xfread(), This is for use with fscanf() and friends.
117FILE *xfopen(const char *path, const char *mode) 117FILE* FAST_FUNC xfopen(const char *path, const char *mode)
118{ 118{
119 FILE *fp = fopen(path, mode); 119 FILE *fp = fopen(path, mode);
120 if (fp == NULL) 120 if (fp == NULL)
@@ -123,7 +123,7 @@ FILE *xfopen(const char *path, const char *mode)
123} 123}
124 124
125// Die if we can't open a file and return a fd. 125// Die if we can't open a file and return a fd.
126int xopen3(const char *pathname, int flags, int mode) 126int FAST_FUNC xopen3(const char *pathname, int flags, int mode)
127{ 127{
128 int ret; 128 int ret;
129 129
@@ -135,13 +135,13 @@ int xopen3(const char *pathname, int flags, int mode)
135} 135}
136 136
137// Die if we can't open an existing file and return a fd. 137// Die if we can't open an existing file and return a fd.
138int xopen(const char *pathname, int flags) 138int FAST_FUNC xopen(const char *pathname, int flags)
139{ 139{
140 return xopen3(pathname, flags, 0666); 140 return xopen3(pathname, flags, 0666);
141} 141}
142 142
143// Warn if we can't open a file and return a fd. 143// Warn if we can't open a file and return a fd.
144int open3_or_warn(const char *pathname, int flags, int mode) 144int FAST_FUNC open3_or_warn(const char *pathname, int flags, int mode)
145{ 145{
146 int ret; 146 int ret;
147 147
@@ -153,24 +153,24 @@ int open3_or_warn(const char *pathname, int flags, int mode)
153} 153}
154 154
155// Warn if we can't open a file and return a fd. 155// Warn if we can't open a file and return a fd.
156int open_or_warn(const char *pathname, int flags) 156int FAST_FUNC open_or_warn(const char *pathname, int flags)
157{ 157{
158 return open3_or_warn(pathname, flags, 0666); 158 return open3_or_warn(pathname, flags, 0666);
159} 159}
160 160
161void xunlink(const char *pathname) 161void FAST_FUNC xunlink(const char *pathname)
162{ 162{
163 if (unlink(pathname)) 163 if (unlink(pathname))
164 bb_perror_msg_and_die("can't remove file '%s'", pathname); 164 bb_perror_msg_and_die("can't remove file '%s'", pathname);
165} 165}
166 166
167void xrename(const char *oldpath, const char *newpath) 167void FAST_FUNC xrename(const char *oldpath, const char *newpath)
168{ 168{
169 if (rename(oldpath, newpath)) 169 if (rename(oldpath, newpath))
170 bb_perror_msg_and_die("can't move '%s' to '%s'", oldpath, newpath); 170 bb_perror_msg_and_die("can't move '%s' to '%s'", oldpath, newpath);
171} 171}
172 172
173int rename_or_warn(const char *oldpath, const char *newpath) 173int FAST_FUNC rename_or_warn(const char *oldpath, const char *newpath)
174{ 174{
175 int n = rename(oldpath, newpath); 175 int n = rename(oldpath, newpath);
176 if (n) 176 if (n)
@@ -178,20 +178,20 @@ int rename_or_warn(const char *oldpath, const char *newpath)
178 return n; 178 return n;
179} 179}
180 180
181void xpipe(int filedes[2]) 181void FAST_FUNC xpipe(int filedes[2])
182{ 182{
183 if (pipe(filedes)) 183 if (pipe(filedes))
184 bb_perror_msg_and_die("can't create pipe"); 184 bb_perror_msg_and_die("can't create pipe");
185} 185}
186 186
187void xdup2(int from, int to) 187void FAST_FUNC xdup2(int from, int to)
188{ 188{
189 if (dup2(from, to) != to) 189 if (dup2(from, to) != to)
190 bb_perror_msg_and_die("can't duplicate file descriptor"); 190 bb_perror_msg_and_die("can't duplicate file descriptor");
191} 191}
192 192
193// "Renumber" opened fd 193// "Renumber" opened fd
194void xmove_fd(int from, int to) 194void FAST_FUNC xmove_fd(int from, int to)
195{ 195{
196 if (from == to) 196 if (from == to)
197 return; 197 return;
@@ -200,7 +200,7 @@ void xmove_fd(int from, int to)
200} 200}
201 201
202// Die with an error message if we can't write the entire buffer. 202// Die with an error message if we can't write the entire buffer.
203void xwrite(int fd, const void *buf, size_t count) 203void FAST_FUNC xwrite(int fd, const void *buf, size_t count)
204{ 204{
205 if (count) { 205 if (count) {
206 ssize_t size = full_write(fd, buf, count); 206 ssize_t size = full_write(fd, buf, count);
@@ -210,7 +210,7 @@ void xwrite(int fd, const void *buf, size_t count)
210} 210}
211 211
212// Die with an error message if we can't lseek to the right spot. 212// Die with an error message if we can't lseek to the right spot.
213off_t xlseek(int fd, off_t offset, int whence) 213off_t FAST_FUNC xlseek(int fd, off_t offset, int whence)
214{ 214{
215 off_t off = lseek(fd, offset, whence); 215 off_t off = lseek(fd, offset, whence);
216 if (off == (off_t)-1) { 216 if (off == (off_t)-1) {
@@ -221,8 +221,8 @@ off_t xlseek(int fd, off_t offset, int whence)
221 return off; 221 return off;
222} 222}
223 223
224// Die with supplied filename if this FILE * has ferror set. 224// Die with supplied filename if this FILE* has ferror set.
225void die_if_ferror(FILE *fp, const char *fn) 225void FAST_FUNC die_if_ferror(FILE *fp, const char *fn)
226{ 226{
227 if (ferror(fp)) { 227 if (ferror(fp)) {
228 /* ferror doesn't set useful errno */ 228 /* ferror doesn't set useful errno */
@@ -231,13 +231,13 @@ void die_if_ferror(FILE *fp, const char *fn)
231} 231}
232 232
233// Die with an error message if stdout has ferror set. 233// Die with an error message if stdout has ferror set.
234void die_if_ferror_stdout(void) 234void FAST_FUNC die_if_ferror_stdout(void)
235{ 235{
236 die_if_ferror(stdout, bb_msg_standard_output); 236 die_if_ferror(stdout, bb_msg_standard_output);
237} 237}
238 238
239// Die with an error message if we have trouble flushing stdout. 239// Die with an error message if we have trouble flushing stdout.
240void xfflush_stdout(void) 240void FAST_FUNC xfflush_stdout(void)
241{ 241{
242 if (fflush(stdout)) { 242 if (fflush(stdout)) {
243 bb_perror_msg_and_die(bb_msg_standard_output); 243 bb_perror_msg_and_die(bb_msg_standard_output);
@@ -245,7 +245,7 @@ void xfflush_stdout(void)
245} 245}
246 246
247 247
248int bb_putchar(int ch) 248int FAST_FUNC bb_putchar(int ch)
249{ 249{
250 /* time.c needs putc(ch, stdout), not putchar(ch). 250 /* time.c needs putc(ch, stdout), not putchar(ch).
251 * it does "stdout = stderr;", but then glibc's putchar() 251 * it does "stdout = stderr;", but then glibc's putchar()
@@ -253,9 +253,9 @@ int bb_putchar(int ch)
253 return putc(ch, stdout); 253 return putc(ch, stdout);
254} 254}
255 255
256/* Die with an error message if we can't copy an entire FILE * to stdout, 256/* Die with an error message if we can't copy an entire FILE* to stdout,
257 * then close that file. */ 257 * then close that file. */
258void xprint_and_close_file(FILE *file) 258void FAST_FUNC xprint_and_close_file(FILE *file)
259{ 259{
260 fflush(stdout); 260 fflush(stdout);
261 // copyfd outputs error messages for us. 261 // copyfd outputs error messages for us.
@@ -267,7 +267,7 @@ void xprint_and_close_file(FILE *file)
267 267
268// Die with an error message if we can't malloc() enough space and do an 268// Die with an error message if we can't malloc() enough space and do an
269// sprintf() into that space. 269// sprintf() into that space.
270char *xasprintf(const char *format, ...) 270char* FAST_FUNC xasprintf(const char *format, ...)
271{ 271{
272 va_list p; 272 va_list p;
273 int r; 273 int r;
@@ -295,7 +295,7 @@ char *xasprintf(const char *format, ...)
295} 295}
296 296
297#if 0 /* If we will ever meet a libc which hasn't [f]dprintf... */ 297#if 0 /* If we will ever meet a libc which hasn't [f]dprintf... */
298int fdprintf(int fd, const char *format, ...) 298int FAST_FUNC fdprintf(int fd, const char *format, ...)
299{ 299{
300 va_list p; 300 va_list p;
301 int r; 301 int r;
@@ -327,7 +327,7 @@ int fdprintf(int fd, const char *format, ...)
327} 327}
328#endif 328#endif
329 329
330void xsetenv(const char *key, const char *value) 330void FAST_FUNC xsetenv(const char *key, const char *value)
331{ 331{
332 if (setenv(key, value, 1)) 332 if (setenv(key, value, 1))
333 bb_error_msg_and_die(bb_msg_memory_exhausted); 333 bb_error_msg_and_die(bb_msg_memory_exhausted);
@@ -336,32 +336,32 @@ void xsetenv(const char *key, const char *value)
336// Die with an error message if we can't set gid. (Because resource limits may 336// Die with an error message if we can't set gid. (Because resource limits may
337// limit this user to a given number of processes, and if that fills up the 337// limit this user to a given number of processes, and if that fills up the
338// setgid() will fail and we'll _still_be_root_, which is bad.) 338// setgid() will fail and we'll _still_be_root_, which is bad.)
339void xsetgid(gid_t gid) 339void FAST_FUNC xsetgid(gid_t gid)
340{ 340{
341 if (setgid(gid)) bb_perror_msg_and_die("setgid"); 341 if (setgid(gid)) bb_perror_msg_and_die("setgid");
342} 342}
343 343
344// Die with an error message if we can't set uid. (See xsetgid() for why.) 344// Die with an error message if we can't set uid. (See xsetgid() for why.)
345void xsetuid(uid_t uid) 345void FAST_FUNC xsetuid(uid_t uid)
346{ 346{
347 if (setuid(uid)) bb_perror_msg_and_die("setuid"); 347 if (setuid(uid)) bb_perror_msg_and_die("setuid");
348} 348}
349 349
350// Die if we can't chdir to a new path. 350// Die if we can't chdir to a new path.
351void xchdir(const char *path) 351void FAST_FUNC xchdir(const char *path)
352{ 352{
353 if (chdir(path)) 353 if (chdir(path))
354 bb_perror_msg_and_die("chdir(%s)", path); 354 bb_perror_msg_and_die("chdir(%s)", path);
355} 355}
356 356
357void xchroot(const char *path) 357void FAST_FUNC xchroot(const char *path)
358{ 358{
359 if (chroot(path)) 359 if (chroot(path))
360 bb_perror_msg_and_die("can't change root directory to %s", path); 360 bb_perror_msg_and_die("can't change root directory to %s", path);
361} 361}
362 362
363// Print a warning message if opendir() fails, but don't die. 363// Print a warning message if opendir() fails, but don't die.
364DIR *warn_opendir(const char *path) 364DIR* FAST_FUNC warn_opendir(const char *path)
365{ 365{
366 DIR *dp; 366 DIR *dp;
367 367
@@ -372,7 +372,7 @@ DIR *warn_opendir(const char *path)
372} 372}
373 373
374// Die with an error message if opendir() fails. 374// Die with an error message if opendir() fails.
375DIR *xopendir(const char *path) 375DIR* FAST_FUNC xopendir(const char *path)
376{ 376{
377 DIR *dp; 377 DIR *dp;
378 378
@@ -383,7 +383,7 @@ DIR *xopendir(const char *path)
383} 383}
384 384
385// Die with an error message if we can't open a new socket. 385// Die with an error message if we can't open a new socket.
386int xsocket(int domain, int type, int protocol) 386int FAST_FUNC xsocket(int domain, int type, int protocol)
387{ 387{
388 int r = socket(domain, type, protocol); 388 int r = socket(domain, type, protocol);
389 389
@@ -404,20 +404,20 @@ USE_FEATURE_IPV6(if (domain == AF_INET6) s = "INET6";)
404} 404}
405 405
406// Die with an error message if we can't bind a socket to an address. 406// Die with an error message if we can't bind a socket to an address.
407void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) 407void FAST_FUNC xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen)
408{ 408{
409 if (bind(sockfd, my_addr, addrlen)) bb_perror_msg_and_die("bind"); 409 if (bind(sockfd, my_addr, addrlen)) bb_perror_msg_and_die("bind");
410} 410}
411 411
412// Die with an error message if we can't listen for connections on a socket. 412// Die with an error message if we can't listen for connections on a socket.
413void xlisten(int s, int backlog) 413void FAST_FUNC xlisten(int s, int backlog)
414{ 414{
415 if (listen(s, backlog)) bb_perror_msg_and_die("listen"); 415 if (listen(s, backlog)) bb_perror_msg_and_die("listen");
416} 416}
417 417
418/* Die with an error message if sendto failed. 418/* Die with an error message if sendto failed.
419 * Return bytes sent otherwise */ 419 * Return bytes sent otherwise */
420ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, 420ssize_t FAST_FUNC xsendto(int s, const void *buf, size_t len, const struct sockaddr *to,
421 socklen_t tolen) 421 socklen_t tolen)
422{ 422{
423 ssize_t ret = sendto(s, buf, len, 0, to, tolen); 423 ssize_t ret = sendto(s, buf, len, 0, to, tolen);
@@ -430,14 +430,14 @@ ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to,
430} 430}
431 431
432// xstat() - a stat() which dies on failure with meaningful error message 432// xstat() - a stat() which dies on failure with meaningful error message
433void xstat(const char *name, struct stat *stat_buf) 433void FAST_FUNC xstat(const char *name, struct stat *stat_buf)
434{ 434{
435 if (stat(name, stat_buf)) 435 if (stat(name, stat_buf))
436 bb_perror_msg_and_die("can't stat '%s'", name); 436 bb_perror_msg_and_die("can't stat '%s'", name);
437} 437}
438 438
439// selinux_or_die() - die if SELinux is disabled. 439// selinux_or_die() - die if SELinux is disabled.
440void selinux_or_die(void) 440void FAST_FUNC selinux_or_die(void)
441{ 441{
442#if ENABLE_SELINUX 442#if ENABLE_SELINUX
443 int rc = is_selinux_enabled(); 443 int rc = is_selinux_enabled();
@@ -451,7 +451,7 @@ void selinux_or_die(void)
451#endif 451#endif
452} 452}
453 453
454int ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) 454int FAST_FUNC ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...)
455{ 455{
456 int ret; 456 int ret;
457 va_list p; 457 va_list p;
@@ -467,7 +467,7 @@ int ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fm
467 return ret; 467 return ret;
468} 468}
469 469
470int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) 470int FAST_FUNC ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...)
471{ 471{
472 va_list p; 472 va_list p;
473 int ret = ioctl(fd, request, argp); 473 int ret = ioctl(fd, request, argp);
@@ -481,7 +481,7 @@ int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...)
481} 481}
482 482
483#if ENABLE_IOCTL_HEX2STR_ERROR 483#if ENABLE_IOCTL_HEX2STR_ERROR
484int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name) 484int FAST_FUNC bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name)
485{ 485{
486 int ret; 486 int ret;
487 487
@@ -490,7 +490,7 @@ int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_nam
490 bb_simple_perror_msg(ioctl_name); 490 bb_simple_perror_msg(ioctl_name);
491 return ret; 491 return ret;
492} 492}
493int bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name) 493int FAST_FUNC bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name)
494{ 494{
495 int ret; 495 int ret;
496 496
@@ -500,7 +500,7 @@ int bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name)
500 return ret; 500 return ret;
501} 501}
502#else 502#else
503int bb_ioctl_or_warn(int fd, unsigned request, void *argp) 503int FAST_FUNC bb_ioctl_or_warn(int fd, unsigned request, void *argp)
504{ 504{
505 int ret; 505 int ret;
506 506
@@ -509,7 +509,7 @@ int bb_ioctl_or_warn(int fd, unsigned request, void *argp)
509 bb_perror_msg("ioctl %#x failed", request); 509 bb_perror_msg("ioctl %#x failed", request);
510 return ret; 510 return ret;
511} 511}
512int bb_xioctl(int fd, unsigned request, void *argp) 512int FAST_FUNC bb_xioctl(int fd, unsigned request, void *argp)
513{ 513{
514 int ret; 514 int ret;
515 515