1 /* Provide a snprintf on Windows for older Visual Studio builds.
2  * VS2013 and older do not support C99 snprintf(). The subsitute _snprintf()
3  * does not correctly NUL-terminate buffers in case of overflow.
4  * This implementation emulates the ISO C99 snprintf() for VS2013 and older.
5  */
6 
7 #if defined(_MSC_VER) && _MSC_VER < 1900
8 
9 #include <stdio.h>
10 #include <stdarg.h>
11 
snprintf(char * buf,size_t len,const char * fmt,...)12 int snprintf(char* buf, size_t len, const char* fmt, ...)
13 {
14   int n;
15   va_list ap;
16   va_start(ap, fmt);
17 
18   n = _vscprintf(fmt, ap);
19   vsnprintf_s(buf, len, _TRUNCATE, fmt, ap);
20 
21   va_end(ap);
22   return n;
23 }
24 
25 #endif
26