diff options
author | Ron Yorston <rmy@pobox.com> | 2019-01-08 15:20:21 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-01-08 15:20:21 +0000 |
commit | 26a1f54837da021aeeb72680acb2feb4ea1e02da (patch) | |
tree | 831899a173b4caa86f904ede75365c772b2b8694 /win32 | |
parent | a85653040477ec4e8a722de3af5afd04ee66bd59 (diff) | |
download | busybox-w32-26a1f54837da021aeeb72680acb2feb4ea1e02da.tar.gz busybox-w32-26a1f54837da021aeeb72680acb2feb4ea1e02da.tar.bz2 busybox-w32-26a1f54837da021aeeb72680acb2feb4ea1e02da.zip |
win32: implement vsnprintf(2)
The Microsoft C runtime may include a defective version of vsnprintf.
Implement a standards-compliant replacement.
Diffstat (limited to 'win32')
-rw-r--r-- | win32/winansi.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/win32/winansi.c b/win32/winansi.c index 167b4b0b1..9e7d10a56 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -552,6 +552,27 @@ int winansi_fputs(const char *str, FILE *stream) | |||
552 | return ansi_emulate(str, stream) == EOF ? EOF : 0; | 552 | return ansi_emulate(str, stream) == EOF ? EOF : 0; |
553 | } | 553 | } |
554 | 554 | ||
555 | #if !defined(__USE_MINGW_ANSI_STDIO) || !__USE_MINGW_ANSI_STDIO | ||
556 | /* | ||
557 | * Prior to Windows 10 vsnprintf was incompatible with the C99 standard. | ||
558 | * Implement a replacement using _vsnprintf. | ||
559 | */ | ||
560 | int winansi_vsnprintf(char *buf, size_t size, const char *format, va_list list) | ||
561 | { | ||
562 | size_t len; | ||
563 | va_list list2; | ||
564 | |||
565 | va_copy(list2, list); | ||
566 | len = _vsnprintf(NULL, 0, format, list2); | ||
567 | if (len < 0) | ||
568 | return -1; | ||
569 | |||
570 | _vsnprintf(buf, size, format, list); | ||
571 | buf[size-1] = '\0'; | ||
572 | return len; | ||
573 | } | ||
574 | #endif | ||
575 | |||
555 | int winansi_vfprintf(FILE *stream, const char *format, va_list list) | 576 | int winansi_vfprintf(FILE *stream, const char *format, va_list list) |
556 | { | 577 | { |
557 | int len, rv; | 578 | int len, rv; |