diff --git a/src/libCom/osi/os/WIN32/osdStdio.c b/src/libCom/osi/os/WIN32/osdStdio.c index d2e43295a..d1fc7d3b8 100644 --- a/src/libCom/osi/os/WIN32/osdStdio.c +++ b/src/libCom/osi/os/WIN32/osdStdio.c @@ -1,11 +1,10 @@ /* osdStdio.c */ /*************************************************************************\ -* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found +* EPICS BASE is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. \*************************************************************************/ @@ -15,33 +14,25 @@ #define epicsExportSharedSymbols #include "epicsStdio.h" -int epicsShareAPI epicsVsnprintf ( - char * str, size_t size, const char *format, va_list ap ) +int epicsShareAPI epicsVsnprintf(char *str, size_t len, + const char *fmt, va_list ap) { - int rtn; + int needed = _vscprintf(fmt, ap); + int retval = _vsnprintf(str, len, fmt, ap); - rtn = _vsnprintf ( str, size, format, ap ); - if ( rtn >= 0 ) { - size_t sizeReturned = (size_t) rtn; - if ( sizeReturned < size ) { - return rtn; - } - } - if ( rtn == -1 ) { - if(size!=0) str[size-1] = 0; - return (int) size; - } - return rtn; + if (len && retval == -1) + str[len - 1] = 0; + + return ((int) len < needed) ? needed : retval; } -int epicsShareAPI epicsSnprintf ( - char *str, size_t size, const char *pFormat, ... ) +int epicsShareAPI epicsSnprintf (char *str, size_t len, const char *fmt, ...) { int rtn; va_list pvar; - va_start ( pvar, pFormat ); - rtn = epicsVsnprintf ( str, size, pFormat, pvar ); - va_end ( pvar ); - return ( rtn ); + va_start (pvar, fmt); + rtn = epicsVsnprintf (str, len, fmt, pvar); + va_end (pvar); + return (rtn); }