diff options
author | 2021-05-10 14:55:20 -0400 | |
---|---|---|
committer | 2021-05-10 14:55:20 -0400 | |
commit | d88d199f23088ac1c3d7696374b0a1c1c1c18358 (patch) | |
tree | 977307e478f76c5de5ca141268cf8ce0309a09eb /lib/libpcap/libpcap/missing/win_snprintf.c | |
parent | 5fd83771641d15c418f747bd343ba6738d3875f7 (diff) | |
download | apple_cmds-d88d199f23088ac1c3d7696374b0a1c1c1c18358.tar.gz apple_cmds-d88d199f23088ac1c3d7696374b0a1c1c1c18358.tar.zst apple_cmds-d88d199f23088ac1c3d7696374b0a1c1c1c18358.zip |
libpcap-98.40.1
Diffstat (limited to 'lib/libpcap/libpcap/missing/win_snprintf.c')
-rw-r--r-- | lib/libpcap/libpcap/missing/win_snprintf.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/libpcap/libpcap/missing/win_snprintf.c b/lib/libpcap/libpcap/missing/win_snprintf.c new file mode 100644 index 0000000..f422403 --- /dev/null +++ b/lib/libpcap/libpcap/missing/win_snprintf.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include <stdarg.h> + +#include "portability.h" + +int +pcap_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. + * + * We don't, however, offer C99 behavior for the return + * value; _vsnprintf_s() returns -1, not the number of + * characters that would have been put into the buffer + * had it been large enough, if the string is truncated. + * The only way to get that value is to use _vscprintf(); + * getting that count isn't worth the re-formatting. + * + * XXX - does _vsnprintf_s() return -1 on a formatting + * error? + */ + str[str_size - 1] = '\0'; + return (ret); +} + +int +pcap_snprintf(char *str, size_t str_size, const char *format, ...) +{ + va_list args; + int ret; + + va_start(args, format); + ret = pcap_vsnprintf(str, str_size, format, args); + va_end(args); + return (ret); +} |