aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/xfuncs.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index 313e32814..4790aa140 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -411,6 +411,37 @@ char *xasprintf(const char *format, ...)
411 return string_ptr; 411 return string_ptr;
412} 412}
413 413
414#ifdef __dietlibc__
415int dprintf(int fd, const char *format, ...)
416{
417 va_list p;
418 int r;
419 char *string_ptr;
420
421#if 1
422 // GNU extension
423 va_start(p, format);
424 r = vasprintf(&string_ptr, format, p);
425 va_end(p);
426#else
427 // Bloat for systems that haven't got the GNU extension.
428 va_start(p, format);
429 r = vsnprintf(NULL, 0, format, p);
430 va_end(p);
431 string_ptr = xmalloc(r+1);
432 va_start(p, format);
433 r = vsnprintf(string_ptr, r+1, format, p);
434 va_end(p);
435#endif
436
437 if (r >= 0) {
438 full_write(fd, string_ptr, r);
439 free(string_ptr);
440 }
441 return r;
442}
443#endif
444
414// Die with an error message if we can't copy an entire FILE * to stdout, then 445// Die with an error message if we can't copy an entire FILE * to stdout, then
415// close that file. 446// close that file.
416void xprint_and_close_file(FILE *file) 447void xprint_and_close_file(FILE *file)