From c8e6e35ba4095846121d5b5a3eee57caa5e8e0fb Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Mon, 18 Dec 2006 22:10:24 +0000 Subject: nc: add missing cast xfuncs: add dprintf for dietlibc --- libbb/xfuncs.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'libbb/xfuncs.c') 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, ...) return string_ptr; } +#ifdef __dietlibc__ +int dprintf(int fd, const char *format, ...) +{ + va_list p; + int r; + char *string_ptr; + +#if 1 + // GNU extension + va_start(p, format); + r = vasprintf(&string_ptr, format, p); + va_end(p); +#else + // Bloat for systems that haven't got the GNU extension. + va_start(p, format); + r = vsnprintf(NULL, 0, format, p); + va_end(p); + string_ptr = xmalloc(r+1); + va_start(p, format); + r = vsnprintf(string_ptr, r+1, format, p); + va_end(p); +#endif + + if (r >= 0) { + full_write(fd, string_ptr, r); + free(string_ptr); + } + return r; +} +#endif + // Die with an error message if we can't copy an entire FILE * to stdout, then // close that file. void xprint_and_close_file(FILE *file) -- cgit v1.2.3