From a19e1d21da1707c55e51db25d97c51743ff2b67e Mon Sep 17 00:00:00 2001 From: Andrew Johnson <anj@aps.anl.gov> Date: Fri, 31 Aug 2012 15:57:59 -0500 Subject: [PATCH] libCom: Fix epicsSnprintf() under MinGW Use the Microsoft _vscprintf() function which was just missing a prototype in earlier versions of MinGW's stdio.h header. --- src/libCom/osi/os/WIN32/osdStdio.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/libCom/osi/os/WIN32/osdStdio.c b/src/libCom/osi/os/WIN32/osdStdio.c index 602651f8b0..8a2d58ea9b 100644 --- a/src/libCom/osi/os/WIN32/osdStdio.c +++ b/src/libCom/osi/os/WIN32/osdStdio.c @@ -11,6 +11,11 @@ #include <stdio.h> #include <stdarg.h> +#ifndef _MSC_VER +/* Older versions of MinGW omitted this prototype from stdio.h */ +_CRTIMP int __cdecl __MINGW_NOTHROW _vscprintf (const char*, va_list); +#endif + #define epicsExportSharedSymbols #include "epicsStdio.h" @@ -18,26 +23,12 @@ int epicsShareAPI epicsVsnprintf(char *str, size_t len, const char *fmt, va_list ap) { int retval = _vsnprintf(str, len, fmt, ap); - -#ifdef _MSC_VER int needed = _vscprintf(fmt, ap); if ((int) len < needed + 1) { str[len - 1] = 0; return needed; } -#else - /* Unfortunately MINGW doesn't provide _vscprintf and their - * _vsnprintf follows MS' broken return value semantics. - */ - if (retval == -1) { - if (len) - str[len - 1] = 0; - return len; - } else if (retval == (int) len) { - str[--retval] = 0; - } -#endif return retval; } -- GitLab