From 7b277a0f97909075505fa6c53bfdaeea02cf62e4 Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Thu, 20 Jul 2017 05:51:19 +0900 Subject: [PATCH] Correct the behavior of snprintfcat() on Windows using posix_vsnprintf() instead of _vsnprintf(). --- misc.c | 10 ++++++---- psqlodbc.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/misc.c b/misc.c index cd8948c..8617080 100644 --- a/misc.c +++ b/misc.c @@ -161,6 +161,10 @@ my_trim(char *s) * snprintfcat is a extension to snprintf * It add format to buf at given pos */ +#ifdef POSIX_SNPRINTF_REQUIRED +static posix_vsnprintf(char *str, size_t size, const char *format, va_list ap); +#define vsnprintf posix_vsnprintf +#endif /* POSIX_SNPRINTF_REQUIRED */ int snprintfcat(char *buf, size_t size, const char *format, ...) @@ -202,8 +206,7 @@ snprintf_len(char *buf, size_t size, const char *format, ...) * and call _snprintf() on that. If it still doesn't fit, enlarge the buffer * and repeat. */ -#ifdef WIN32 -#if (_MSC_VER < 1900) /* vc14 provieds snprintf() */ +#ifdef POSIX_SNPRINTF_REQUIRED static int posix_vsnprintf(char *str, size_t size, const char *format, va_list ap) { @@ -249,8 +252,7 @@ posix_snprintf(char *buf, size_t size, const char *format, ...) va_end(arglist); return len; } -#endif /* _MSC_VER */ -#endif /* WIN32 */ +#endif /* POSIX_SNPRINTF_REQUIRED */ #ifndef HAVE_STRLCAT size_t diff --git a/psqlodbc.h b/psqlodbc.h index 0d7c1a1..87a1cf7 100644 --- a/psqlodbc.h +++ b/psqlodbc.h @@ -233,9 +233,9 @@ typedef double SDOUBLE; #endif /* FALSE */ #else #if (_MSC_VER < 1900) /* vc12 or under */ +#define POSIX_SNPRINTF_REQUIRED #define snprintf posix_snprintf extern int posix_snprintf(char *buf, size_t size, const char *format, ...); -#define vsnprintf _vsnprintf #endif /* _MSC_VER */ #ifndef strdup -- 2.39.5