From 608e091d9a44f562d8b240d9602cbb268eab1b6d Mon Sep 17 00:00:00 2001 From: Darryl Green Date: Wed, 17 Oct 2018 14:48:27 +0100 Subject: [PATCH] Add pre Visual Studio 2015 support to psa_constant_names snprintf was only added in Visual Studio 2015. This adds support for building using Visual Studio versions prior to 2015. This implementation of snprintf has been taken from platform.c --- programs/psa/psa_constant_names.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/programs/psa/psa_constant_names.c b/programs/psa/psa_constant_names.c index 88821dab5..dd19677c4 100644 --- a/programs/psa/psa_constant_names.c +++ b/programs/psa/psa_constant_names.c @@ -4,6 +4,35 @@ #include "psa/crypto.h" +/* This block is present to support Visual Studio builds prior to 2015 */ +#if defined(_MSC_VER) && _MSC_VER < 1900 +#include +int snprintf( char *s, size_t n, const char *fmt, ... ) +{ + int ret; + va_list argp; + + /* Avoid calling the invalid parameter handler by checking ourselves */ + if( s == NULL || n == 0 || fmt == NULL ) + return( -1 ); + + va_start( argp, fmt ); +#if defined(_TRUNCATE) && !defined(__MINGW32__) + ret = _vsnprintf_s( s, n, _TRUNCATE, fmt, argp ); +#else + ret = _vsnprintf( s, n, fmt, argp ); + if( ret < 0 || (size_t) ret == n ) + { + s[n-1] = '\0'; + ret = -1; + } +#endif + va_end( argp ); + + return( ret ); +} +#endif + /* There are different GET_HASH macros for different kinds of algorithms * built from hashes, but the values are all constructed on the * same model. */