summaryrefslogtreecommitdiff
path: root/missing
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-01-29 15:48:55 -0800
committerGuy Harris <guy@alum.mit.edu>2018-01-29 15:48:55 -0800
commitc499612a7f1024a183d0200ef5f1ea7fba63a3e4 (patch)
tree5ffc65612e07d03e445e58a02d9e349c13eb0af7 /missing
parent1e120597d2cb5864d52ca99ca6e167f2454c3153 (diff)
downloadtcpdump-c499612a7f1024a183d0200ef5f1ea7fba63a3e4.tar.gz
Add nd_{v}snprintf() routines/wrappers.
Some versions of the MSVC runtime library have a non-C99-compliant vsnprintf(), which we want to avoid. On Windows, use snprintf() and vsnprintf() for VS 2015 and later, where they both exist in C99-compliant forms, and wrap _{v}snprintf_s() otherwise (they're guaranteed to do the null termination that we want).
Diffstat (limited to 'missing')
-rw-r--r--missing/getservent.c4
-rw-r--r--missing/snprintf.c14
-rw-r--r--missing/win_ether_ntohost.c4
-rw-r--r--missing/win_snprintf.c31
4 files changed, 11 insertions, 42 deletions
diff --git a/missing/getservent.c b/missing/getservent.c
index 39cee068..198644f2 100644
--- a/missing/getservent.c
+++ b/missing/getservent.c
@@ -65,9 +65,9 @@ const char *etc_path(const char *file)
return (file);
else
#ifdef _WIN32
- snprintf(path, sizeof(path), "%s%s%s", env, __PATH_ETC_INET, file);
+ nd_snprintf(path, sizeof(path), "%s%s%s", env, __PATH_ETC_INET, file);
#else
- snprintf(path, sizeof(path), "%s%s", env, file);
+ nd_snprintf(path, sizeof(path), "%s%s", env, file);
#endif
return (path);
}
diff --git a/missing/snprintf.c b/missing/snprintf.c
index 921b74c1..3b21f31f 100644
--- a/missing/snprintf.c
+++ b/missing/snprintf.c
@@ -456,13 +456,13 @@ xyzprintf (struct state *state, const char *char_format, va_list ap)
#ifndef HAVE_SNPRINTF
int
-snprintf (char *str, size_t sz, const char *format, ...)
+nd_snprintf (char *str, size_t sz, const char *format, ...)
{
va_list args;
int ret;
va_start(args, format);
- ret = vsnprintf (str, sz, format, args);
+ ret = nd_vsnprintf (str, sz, format, args);
#ifdef PARANOIA
{
@@ -518,13 +518,13 @@ asprintf (char **ret, const char *format, ...)
#ifndef HAVE_ASNPRINTF
int
-asnprintf (char **ret, size_t max_sz, const char *format, ...)
+nd_asnprintf (char **ret, size_t max_sz, const char *format, ...)
{
va_list args;
int val;
va_start(args, format);
- val = vasnprintf (ret, max_sz, format, args);
+ val = nd_vasnprintf (ret, max_sz, format, args);
#ifdef PARANOIA
{
@@ -550,14 +550,14 @@ asnprintf (char **ret, size_t max_sz, const char *format, ...)
int
vasprintf (char **ret, const char *format, va_list args)
{
- return vasnprintf (ret, 0, format, args);
+ return nd_vasnprintf (ret, 0, format, args);
}
#endif
#ifndef HAVE_VASNPRINTF
int
-vasnprintf (char **ret, size_t max_sz, const char *format, va_list args)
+nd_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args)
{
int st;
size_t len;
@@ -600,7 +600,7 @@ vasnprintf (char **ret, size_t max_sz, const char *format, va_list args)
#ifndef HAVE_VSNPRINTF
int
-vsnprintf (char *str, size_t sz, const char *format, va_list args)
+nd_vsnprintf (char *str, size_t sz, const char *format, va_list args)
{
struct state state;
int ret;
diff --git a/missing/win_ether_ntohost.c b/missing/win_ether_ntohost.c
index 05930923..6ac26b7c 100644
--- a/missing/win_ether_ntohost.c
+++ b/missing/win_ether_ntohost.c
@@ -85,9 +85,9 @@ const char *etc_path (const char *file)
return (file);
if (win9x)
- snprintf (path, sizeof(path), "%s\\etc\\%s", env, file);
+ nd_snprintf (path, sizeof(path), "%s\\etc\\%s", env, file);
else
- snprintf (path, sizeof(path), "%s\\system32\\drivers\\etc\\%s", env, file);
+ nd_snprintf (path, sizeof(path), "%s\\system32\\drivers\\etc\\%s", env, file);
return (path);
}
diff --git a/missing/win_snprintf.c b/missing/win_snprintf.c
deleted file mode 100644
index 17dc633c..00000000
--- a/missing/win_snprintf.c
+++ /dev/null
@@ -1,31 +0,0 @@
-#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);
-}