Wrapper for MSC < VS2015

This commit is contained in:
Eric Blankenhorn
2019-03-08 10:55:34 -06:00
parent be83a54f22
commit d26a6b59a3
2 changed files with 29 additions and 17 deletions

View File

@ -124,11 +124,6 @@ static int loggingEnabled = 0;
static struct log mynewt_log; static struct log mynewt_log;
#endif /* WOLFSSL_APACHE_MYNEWT */ #endif /* WOLFSSL_APACHE_MYNEWT */
#ifdef _MSC_VER
/* 4996 warning to use MS extensions e.g., sprintf_s instead of XSPRINTF */
#pragma warning(disable: 4996)
#endif /* _MSC_VER */
#endif /* DEBUG_WOLFSSL */ #endif /* DEBUG_WOLFSSL */

View File

@ -391,18 +391,35 @@
#endif #endif
#define XSNPRINTF snprintf #define XSNPRINTF snprintf
#else #else
#if defined(_MSC_VER) && (_MSC_VER >= 1900) #ifdef _MSC_VER
/* Beginning with the UCRT in Visual Studio 2015 and #if (_MSC_VER >= 1900)
Windows 10, snprintf is no longer identical to /* Beginning with the UCRT in Visual Studio 2015 and
_snprintf. The snprintf function behavior is now Windows 10, snprintf is no longer identical to
C99 standard compliant. */ _snprintf. The snprintf function behavior is now
#define XSNPRINTF snprintf C99 standard compliant. */
#else #define XSNPRINTF snprintf
/* _snprintf only null terminates the string if return len #else
is less than count */ /* 4996 warning to use MS extensions e.g., _sprintf_s
#define XSNPRINTF _snprintf instead of _snprintf */
#endif #pragma warning(disable: 4996)
#endif static WC_INLINE
int xsnprintf(char *buffer, size_t bufsize,
const char *format, ...) {
va_list ap;
int ret;
if ((int)bufsize <= 0) return -1;
va_start(ap, format);
ret = vsnprintf(buffer, bufsize, format, ap);
if (ret >= (int)bufsize)
ret = -1;
va_end(ap);
return ret;
}
#define XSNPRINTF xsnprintf
#endif /* (_MSC_VER >= 1900) */
#endif /* _MSC_VER */
#endif /* USE_WINDOWS_API */
#if defined(WOLFSSL_CERT_EXT) || defined(HAVE_ALPN) #if defined(WOLFSSL_CERT_EXT) || defined(HAVE_ALPN)
/* use only Thread Safe version of strtok */ /* use only Thread Safe version of strtok */