diff options
author | Erik de Castro Lopo <erikd@mega-nerd.com> | 2014-09-22 18:29:32 +1000 |
---|---|---|
committer | Erik de Castro Lopo <erikd@mega-nerd.com> | 2014-09-22 18:29:36 +1000 |
commit | 1c7e3f100f4ff51be2ac85a1d21d2b6f2926ea39 (patch) | |
tree | f15ea190d793ef717ffee42406bc116bd66be9f7 /src/share/grabbag | |
parent | e0ac5d46f0e8d3b3394d794f1e2ec201b0043c94 (diff) | |
download | flac-1c7e3f100f4ff51be2ac85a1d21d2b6f2926ea39.tar.gz |
Windows specific vsnprintf fixes.
* Changes flac_snprintf (in src/share/grabbag/snprintf.c) and its copy
local_snprintf (src/libFLAC/metadata_iterators.c) to be almost sane.
* Adds flac_vsnprintf (src/share/grabbag/snprintf.c) and its copy
local_vsnprintf (src/share/win_utf8_io/win_utf8_io.c).
* Changes stats_print_info in src/flac/utils.c so it uses flac_vsnprintf
instead of vsnprintf. This makes return value checking unnecessary.
Patch-from: lvqcl <lvqcl.mail@gmail.com>
Diffstat (limited to 'src/share/grabbag')
-rw-r--r-- | src/share/grabbag/snprintf.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/share/grabbag/snprintf.c b/src/share/grabbag/snprintf.c index 3a0661f0..d19e42c1 100644 --- a/src/share/grabbag/snprintf.c +++ b/src/share/grabbag/snprintf.c @@ -49,7 +49,7 @@ * does not over-write the end of the buffer. MS's snprintf_s in this case * returns -1. * - * The _MSC_VER code below attempts to modify the return code for snprintf_s + * The _MSC_VER code below attempts to modify the return code for vsnprintf_s * to something that is more compatible with the behaviour of the ISO C version. */ @@ -57,13 +57,18 @@ int flac_snprintf(char *str, size_t size, const char *fmt, ...) { va_list va; - int rc ; + int rc; va_start (va, fmt); -#ifdef _MSC_VER +#if defined _MSC_VER + if (size == 0) + return 1024; rc = vsnprintf_s (str, size, _TRUNCATE, fmt, va); - rc = (rc > 0) ? rc : (size == 0 ? 1024 : size * 2); + if (rc < 0) + rc = size - 1; +#elif defined __MINGW32__ + rc = __mingw_vsnprintf (str, size, fmt, va); #else rc = vsnprintf (str, size, fmt, va); #endif @@ -71,3 +76,23 @@ flac_snprintf(char *str, size_t size, const char *fmt, ...) return rc; } + +int +flac_vsnprintf(char *str, size_t size, const char *fmt, va_list va) +{ + int rc; + +#if defined _MSC_VER + if (size == 0) + return 1024; + rc = vsnprintf_s (str, size, _TRUNCATE, fmt, va); + if (rc < 0) + rc = size - 1; +#elif defined __MINGW32__ + rc = __mingw_vsnprintf (str, size, fmt, va); +#else + rc = vsnprintf (str, size, fmt, va); +#endif + + return rc; +} |