aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-03-26 12:47:40 +0100
committerRon Yorston <rmy@pobox.com>2012-03-26 12:47:40 +0100
commitb11062c28d3b8b9401effcc9fd7a7f76d920461f (patch)
tree1919ed663659342e9ee082482b2e8468764e85ad
parent83fefff167c161716ba4a40aa4f0dce96cfd3498 (diff)
downloadbusybox-w32-b11062c28d3b8b9401effcc9fd7a7f76d920461f.tar.gz
busybox-w32-b11062c28d3b8b9401effcc9fd7a7f76d920461f.tar.bz2
busybox-w32-b11062c28d3b8b9401effcc9fd7a7f76d920461f.zip
MinGW snprintf/vsnprintf work properly
-rw-r--r--include/mingw.h12
-rw-r--r--libbb/platform.c15
-rw-r--r--libbb/xfuncs_printf.c14
3 files changed, 13 insertions, 28 deletions
diff --git a/include/mingw.h b/include/mingw.h
index 89268d62b..b281a4b49 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -1,5 +1,17 @@
1#include <sys/utime.h> 1#include <sys/utime.h>
2 2
3/*
4 * MS Windows has broken versions of snprintf/vsnprintf that return -1 if
5 * the string is too large for the buffer and don't null terminate the
6 * string if it fills the buffer. However, if we're using a sufficiently
7 * modern version of MinGW and have an appropriate source code qualifier
8 * (such as _GNU_SOURCE) MinGW will use its own standards-compliant
9 * implementation. Check for this.
10 */
11#if !defined(__USE_MINGW_ANSI_STDIO)
12#error "Must use MinGW stdio for snprintf/vsnprintf"
13#endif
14
3#define NOIMPL(name,...) static inline int name(__VA_ARGS__) { errno = ENOSYS; return -1; } 15#define NOIMPL(name,...) static inline int name(__VA_ARGS__) { errno = ENOSYS; return -1; }
4#define IMPL(name,ret,retval,...) static inline ret name(__VA_ARGS__) { return retval; } 16#define IMPL(name,ret,retval,...) static inline ret name(__VA_ARGS__) { return retval; }
5 17
diff --git a/libbb/platform.c b/libbb/platform.c
index 3cb41347f..2bf34f5bc 100644
--- a/libbb/platform.c
+++ b/libbb/platform.c
@@ -51,21 +51,8 @@ int dprintf(int fd, const char *format, ...)
51 char *string_ptr; 51 char *string_ptr;
52 52
53 va_start(p, format); 53 va_start(p, format);
54 if (ENABLE_PLATFORM_MINGW32) { 54 r = vasprintf(&string_ptr, format, p);
55 string_ptr = xmalloc(1024);
56 r = vsnprintf(string_ptr, 1024, format, p);
57 }
58 else
59 r = vasprintf(&string_ptr, format, p);
60 va_end(p); 55 va_end(p);
61 if (ENABLE_PLATFORM_MINGW32 && r > 0) {
62 free(string_ptr);
63 r += 2;
64 string_ptr = xmalloc(r);
65 va_start(p, format);
66 r = vsnprintf(string_ptr, r, format, p);
67 va_end(p);
68 }
69 if (r >= 0) { 56 if (r >= 0) {
70 r = full_write(fd, string_ptr, r); 57 r = full_write(fd, string_ptr, r);
71 free(string_ptr); 58 free(string_ptr);
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index 70d3fc96c..d8a42ba0b 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -295,22 +295,8 @@ char* FAST_FUNC xasprintf(const char *format, ...)
295 char *string_ptr; 295 char *string_ptr;
296 296
297 va_start(p, format); 297 va_start(p, format);
298#if ENABLE_PLATFORM_MINGW32
299 string_ptr = xmalloc(1024);
300 r = vsnprintf(string_ptr, 1024, format, p);
301 va_end(p);
302 if (r > 0) {
303 free(string_ptr);
304 r += 2;
305 string_ptr = xmalloc(r);
306 va_start(p, format);
307 r = vsnprintf(string_ptr, r, format, p);
308 va_end(p);
309 }
310#else
311 r = vasprintf(&string_ptr, format, p); 298 r = vasprintf(&string_ptr, format, p);
312 va_end(p); 299 va_end(p);
313#endif
314 300
315 if (r < 0) 301 if (r < 0)
316 bb_error_msg_and_die(bb_msg_memory_exhausted); 302 bb_error_msg_and_die(bb_msg_memory_exhausted);