From 7bef74b53fe4a400847c9bc60e6fcffa4b6ef4c4 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Thu, 19 Jun 2014 03:04:28 +0400 Subject: [PATCH] Fix unresolved vsnprintf in misc.c and snprintf in cordtest (DJGPP, VC) * cord/tests/cordtest.c (GC_SNPRINTF, GC_SNPRINTF_BUFSZ_ARG): New macro to workaround snprintf() missing in DJGPP and MS VC. * cord/tests/cordtest.c (test_printf): Replace snprintf() with GC_SNPRINTF and GC_SNPRINTF_BUFSZ_ARG. * misc.c (GC_VSNPRINTF): Test DJGPP instead of NO_VSNPRINTF; refine comment. --- cord/tests/cordtest.c | 22 ++++++++++++++++++++-- misc.c | 4 ++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cord/tests/cordtest.c b/cord/tests/cordtest.c index cf5c6966..a5a0c30e 100644 --- a/cord/tests/cordtest.c +++ b/cord/tests/cordtest.c @@ -204,6 +204,24 @@ void test_extras(void) } } +#ifdef __DJGPP__ + /* snprintf is missing in DJGPP (v2.0.3) */ +# define GC_SNPRINTF sprintf +# define GC_SNPRINTF_BUFSZ_ARG(bufsz) /* empty */ +#else +# if defined(_MSC_VER) +# if defined(_WIN32_WCE) + /* _snprintf is deprecated in WinCE */ +# define GC_SNPRINTF StringCchPrintfA +# else +# define GC_SNPRINTF _snprintf +# endif +# else +# define GC_SNPRINTF snprintf +# endif +# define GC_SNPRINTF_BUFSZ_ARG(bufsz) (bufsz), +#endif + void test_printf(void) { CORD result; @@ -226,8 +244,8 @@ void test_printf(void) x = CORD_cat(x,x); if (CORD_sprintf(&result, "->%-120.78r!\n", x) != 124) ABORT("CORD_sprintf failed 3"); - (void)snprintf(result2, sizeof(result2), "->%-120.78s!\n", - CORD_to_char_star(x)); + (void)GC_SNPRINTF(result2, GC_SNPRINTF_BUFSZ_ARG(sizeof(result2)) + "->%-120.78s!\n", CORD_to_char_star(x)); result2[sizeof(result2) - 1] = '\0'; if (CORD_cmp(result, result2) != 0)ABORT("CORD_sprintf goofed 5"); } diff --git a/misc.c b/misc.c index f41384b2..01a7d841 100644 --- a/misc.c +++ b/misc.c @@ -1505,8 +1505,8 @@ GC_API void GC_CALL GC_enable_incremental(void) #define BUFSZ 1024 -#ifdef NO_VSNPRINTF - /* In case this function is missing (e.g., in DJGPP v2.0.3). */ +#ifdef DJGPP + /* vsnprintf is missing in DJGPP (v2.0.3) */ # define GC_VSNPRINTF(buf, bufsz, format, args) vsprintf(buf, format, args) #elif defined(_MSC_VER) # ifdef MSWINCE -- 2.40.0