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
This commit is contained in:
Darryl Green 2018-10-17 14:48:27 +01:00
parent 1824696681
commit 608e091d9a

View file

@ -4,6 +4,35 @@
#include "psa/crypto.h" #include "psa/crypto.h"
/* This block is present to support Visual Studio builds prior to 2015 */
#if defined(_MSC_VER) && _MSC_VER < 1900
#include <stdarg.h>
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 /* There are different GET_HASH macros for different kinds of algorithms
* built from hashes, but the values are all constructed on the * built from hashes, but the values are all constructed on the
* same model. */ * same model. */