libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 913ced4bdd28c16b62e1847cb035b6036b569ffc
parent 2a2a389a340561ff886d8349bb2802c99892c92d
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Mon, 22 Dec 2014 19:42:08 +0000

[w32] Add W32 emulation for snprintf()

Diffstat:
Msrc/include/w32functions.h | 3+++
Msrc/platform/w32functions.c | 26++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/src/include/w32functions.h b/src/include/w32functions.h @@ -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 diff --git a/src/platform/w32functions.c b/src/platform/w32functions.c @@ -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; +}