aboutsummaryrefslogtreecommitdiff
path: root/portability.h
diff options
context:
space:
mode:
Diffstat (limited to 'portability.h')
-rw-r--r--portability.h70
1 files changed, 29 insertions, 41 deletions
diff --git a/portability.h b/portability.h
index 543846e8bd25..84d0778a5c77 100644
--- a/portability.h
+++ b/portability.h
@@ -52,7 +52,7 @@ extern "C" {
#if defined(_MSC_VER) || defined(__MINGW32__)
/*
* strncat_s() is supported at least back to Visual
- * Studio 2005.
+ * Studio 2005; we require Visual Studio 2015 or later.
*/
#define pcap_strlcat(x, y, z) \
strncat_s((x), (z), (y), _TRUNCATE)
@@ -70,7 +70,7 @@ extern "C" {
#if defined(_MSC_VER) || defined(__MINGW32__)
/*
* strncpy_s() is supported at least back to Visual
- * Studio 2005.
+ * Studio 2005; we require Visual Studio 2015 or later.
*/
#define pcap_strlcpy(x, y, z) \
strncpy_s((x), (z), (y), _TRUNCATE)
@@ -83,8 +83,6 @@ extern "C" {
#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
@@ -97,43 +95,9 @@ extern "C" {
#endif
/*
- * On Windows, snprintf(), with that name and with C99 behavior - i.e.,
- * guaranteeing that the formatted string is null-terminated - didn't
- * appear until Visual Studio 2015. Prior to that, the C runtime had
- * only _snprintf(), which *doesn't* guarantee that the string is
- * null-terminated if it is truncated due to the buffer being too
- * small. We therefore can't just define snprintf to be _snprintf
- * and define vsnprintf to be _vsnprintf, as we're relying on null-
- * termination of strings in all cases.
- *
- * We also want to allow this to be built with versions of Visual Studio
- * prior to VS 2015, so we can't rely on snprintf() being present.
- *
- * And we want to make sure that, if we support plugins in the future,
- * a routine with C99 snprintf() behavior will be available to them.
- * We also don't want it to collide with the C library snprintf() if
- * there is one.
- *
- * So we make pcap_snprintf() and pcap_vsnprintf() available, either by
- * #defining them to be snprintf or vsnprintf, respectively, or by
- * defining our own versions and exporting them.
- */
-#ifdef HAVE_SNPRINTF
-#define pcap_snprintf snprintf
-#else
-extern int pcap_snprintf(char *, size_t, PCAP_FORMAT_STRING(const char *), ...)
- PCAP_PRINTFLIKE(3, 4);
-#endif
-
-#ifdef HAVE_VSNPRINTF
-#define pcap_vsnprintf vsnprintf
-#else
-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.
+ * We want asprintf(), for some cases where we use it to construct
+ * dynamically-allocated variable-length strings; it's present on
+ * some, but not all, platforms.
*/
#ifdef HAVE_ASPRINTF
#define pcap_asprintf asprintf
@@ -148,6 +112,30 @@ extern int pcap_asprintf(char **, PCAP_FORMAT_STRING(const char *), ...)
extern int pcap_vasprintf(char **, const char *, va_list ap);
#endif
+/* For Solaris before 11. */
+#ifndef timeradd
+#define timeradd(a, b, result) \
+ do { \
+ (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
+ (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
+ if ((result)->tv_usec >= 1000000) { \
+ ++(result)->tv_sec; \
+ (result)->tv_usec -= 1000000; \
+ } \
+ } while (0)
+#endif /* timeradd */
+#ifndef timersub
+#define timersub(a, b, result) \
+ do { \
+ (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
+ (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
+ if ((result)->tv_usec < 0) { \
+ --(result)->tv_sec; \
+ (result)->tv_usec += 1000000; \
+ } \
+ } while (0)
+#endif /* timersub */
+
#ifdef HAVE_STRTOK_R
#define pcap_strtok_r strtok_r
#else