diff options
author | Guy Harris <guy@alum.mit.edu> | 2018-01-28 20:57:15 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2018-01-28 20:57:15 -0800 |
commit | b3703ed9cfac43b0026fc2e2013e1612edad4300 (patch) | |
tree | edf46516bcff6163fc4258c0d20665d3707a8c87 /missing | |
parent | a909db55ebc50de487e65f19b3250d0b45763d2d (diff) | |
download | tcpdump-b3703ed9cfac43b0026fc2e2013e1612edad4300.tar.gz |
Pick up Windows snprintf and strdup replacements from libpcap.
Diffstat (limited to 'missing')
-rw-r--r-- | missing/win_snprintf.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/missing/win_snprintf.c b/missing/win_snprintf.c new file mode 100644 index 00000000..17dc633c --- /dev/null +++ b/missing/win_snprintf.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <stdarg.h> + +int +vsnprintf(char *str, size_t str_size, const char *format, va_list args) +{ + int ret; + + ret = _vsnprintf_s(str, str_size, _TRUNCATE, format, args); + + /* + * XXX - _vsnprintf() and _snprintf() do *not* guarantee + * that str is null-terminated, but C99's vsnprintf() + * and snprintf() do, and we want to offer C99 behavior, + * so forcibly null-terminate the string. + */ + str[str_size - 1] = '\0'; + return (ret); +} + +int +snprintf(char *str, size_t str_size, const char *format, ...) +{ + va_list args; + int ret; + + va_start(args, format); + ret = vsnprintf(str, str_size, format, args); + va_end(args); + return (ret); +} |