summaryrefslogtreecommitdiffstats
path: root/freebsd/contrib/libpcap/portability.h
diff options
context:
space:
mode:
Diffstat (limited to 'freebsd/contrib/libpcap/portability.h')
-rw-r--r--freebsd/contrib/libpcap/portability.h91
1 files changed, 52 insertions, 39 deletions
diff --git a/freebsd/contrib/libpcap/portability.h b/freebsd/contrib/libpcap/portability.h
index b3612542..543846e8 100644
--- a/freebsd/contrib/libpcap/portability.h
+++ b/freebsd/contrib/libpcap/portability.h
@@ -38,6 +38,7 @@
* Helpers for portability between Windows and UN*X and between different
* flavors of UN*X.
*/
+#include <stdarg.h> /* we declare varargs functions on some platforms */
#include "pcap/funcattrs.h"
@@ -45,49 +46,45 @@
extern "C" {
#endif
-#ifndef HAVE_STRLCPY
- /*
- * Macro that does the same thing as strlcpy().
- */
- #if defined(_MSC_VER) || defined(__MINGW32__)
- /*
- * strncpy_s() is supported at least back to Visual
- * Studio 2005.
- */
- #define strlcpy(x, y, z) \
- strncpy_s((x), (z), (y), _TRUNCATE)
-
- #else
- #define strlcpy(x, y, z) \
- (strncpy((x), (y), (z)), \
- ((z) <= 0 ? 0 : ((x)[(z) - 1] = '\0')), \
- (void) strlen((y)))
- #endif
+#ifdef HAVE_STRLCAT
+ #define pcap_strlcat strlcat
+#else
+ #if defined(_MSC_VER) || defined(__MINGW32__)
+ /*
+ * strncat_s() is supported at least back to Visual
+ * Studio 2005.
+ */
+ #define pcap_strlcat(x, y, z) \
+ strncat_s((x), (z), (y), _TRUNCATE)
+ #else
+ /*
+ * Define it ourselves.
+ */
+ extern size_t pcap_strlcat(char * restrict dst, const char * restrict src, size_t dstsize);
+ #endif
#endif
-#ifndef HAVE_STRLCAT
- /*
- * Macro that does the same thing as strlcat().
- */
- #if defined(_MSC_VER) || defined(__MINGW32__)
- /*
- * strncat_s() is supported at least back to Visual
- * Studio 2005.
- */
- #define strlcat(x, y, z) \
- strncat_s((x), (z), (y), _TRUNCATE)
- #else
- /*
- * ANSI C says strncat() always null-terminates its first argument,
- * so 1) we don't need to explicitly null-terminate the string
- * ourselves and 2) we need to leave room for the null terminator.
- */
- #define strlcat(x, y, z) \
- strncat((x), (y), (z) - strlen((x)) - 1)
- #endif
+#ifdef HAVE_STRLCPY
+ #define pcap_strlcpy strlcpy
+#else
+ #if defined(_MSC_VER) || defined(__MINGW32__)
+ /*
+ * strncpy_s() is supported at least back to Visual
+ * Studio 2005.
+ */
+ #define pcap_strlcpy(x, y, z) \
+ strncpy_s((x), (z), (y), _TRUNCATE)
+ #else
+ /*
+ * Define it ourselves.
+ */
+ extern size_t pcap_strlcpy(char * restrict dst, const char * restrict src, size_t dstsize);
+ #endif
#endif
#ifdef _MSC_VER
+ #define isascii __isascii
+
/*
* If <crtdbg.h> has been included, and _DEBUG is defined, and
* __STDC__ is zero, <crtdbg.h> will define strdup() to call
@@ -134,6 +131,23 @@ extern int pcap_snprintf(char *, size_t, PCAP_FORMAT_STRING(const char *), ...)
extern int pcap_vsnprintf(char *, size_t, const char *, va_list ap);
#endif
+/*
+ * We also want asprintf(), for some cases where we use it to construct
+ * dynamically-allocated variable-length strings.
+ */
+#ifdef HAVE_ASPRINTF
+#define pcap_asprintf asprintf
+#else
+extern int pcap_asprintf(char **, PCAP_FORMAT_STRING(const char *), ...)
+ PCAP_PRINTFLIKE(2, 3);
+#endif
+
+#ifdef HAVE_VASPRINTF
+#define pcap_vasprintf vasprintf
+#else
+extern int pcap_vasprintf(char **, const char *, va_list ap);
+#endif
+
#ifdef HAVE_STRTOK_R
#define pcap_strtok_r strtok_r
#else
@@ -146,7 +160,6 @@ extern int pcap_vsnprintf(char *, size_t, const char *, va_list ap);
/*
* Define it ourselves.
*/
- #define NEED_STRTOK_R
extern char *pcap_strtok_r(char *, const char *, char **);
#endif
#endif /* HAVE_STRTOK_R */