[w32] Add W32 emulation for snprintf()

This commit is contained in:
Evgeny Grin (Karlson2k) committed 2014-12-22 19:42:08 +00:00
1 parent 2a2a389a34
commit 913ced4bdd
2 files changed
+29

No files matched your search

+3
View File
@@ -191,6 +191,9 @@ int MHD_W32_pair_of_sockets_(SOCKET sockets_pair[2]);
*/
int MHD_W32_random_(void);
/* Emulate snprintf function on W32 */
int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, ...);
#ifdef __cplusplus
}
#endif
+26
View File
@@ -29,6 +29,8 @@
#include <string.h>
#include <stdint.h>
#include <time.h>
#include <stdio.h>
#include <stdarg.h>
/**
@@ -640,3 +642,27 @@ int MHD_W32_random_(void)
& 0x7fffffff;
return (int)rnd_val;
}
/* Emulate snprintf function on W32 */
int W32_snprintf(char *__restrict s, size_t n, const char *__restrict format, ...)
{
int ret;
va_list args;
if (0 != n && NULL != s )
{
va_start(args, format);
ret = _vsnprintf(s, n, format, args);
va_end(args);
if (n == ret)
s[n - 1] = 0;
if (ret >= 0)
return ret;
}
va_start(args, format);
ret = _vscprintf(format, args);
va_end(args);
if (0 <= ret && 0 != n && NULL == s)
return -1;
return ret;
}