X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/14c81f0a4aa300f7ea23af6130469f97d8b18793..a15e52bb2722f9c9719cd9909d70c03a10e170c4:/netdissect-stdinc.h diff --git a/netdissect-stdinc.h b/netdissect-stdinc.h index 9b88ce9e..c7c53db4 100644 --- a/netdissect-stdinc.h +++ b/netdissect-stdinc.h @@ -85,6 +85,11 @@ typedef unsigned long long uint64_t; typedef long long int64_t; #endif + + /* + * We have _strtoi64(). Use that for strtoint64_t(). + */ + #define strtoint64_t _strtoi64 #endif /* @@ -163,6 +168,42 @@ #include #include +#ifdef _MSC_VER + /* + * Compiler is MSVC. + */ + #if _MSC_VER >= 1800 + /* + * VS 2013 or newer; we have strtoll(). Use that for strtoint64_t(). + */ + #define strtoint64_t strtoll + #else + /* + * Earlier VS; we don't have strtoll(), but we do have + * _strtoi64(). Use that for strtoint64_t(). + */ + #define strtoint64_t _strtoi64 + #endif + + /* + * Microsoft's documentation doesn't speak of LL as a valid + * suffix for 64-bit integers, so we'll just use i64. + */ + #define INT64_T_CONSTANT(constant) (constant##i64) +#else + /* + * Non-Microsoft compiler. + * + * XXX - should we use strtoll or should we use _strtoi64()? + */ + #define strtoint64_t strtoll + + /* + * Assume LL works. + */ + #define INT64_T_CONSTANT(constant) (constant##LL) +#endif + #ifdef _MSC_VER #define stat _stat #define open _open @@ -179,7 +220,7 @@ #define inline __inline #endif -#ifdef AF_INET6 +#if defined(AF_INET6) && !defined(HAVE_OS_IPV6_SUPPORT) #define HAVE_OS_IPV6_SUPPORT #endif @@ -200,7 +241,6 @@ typedef char* caddr_t; #define MAXHOSTNAMELEN 64 #define snprintf _snprintf #define vsnprintf _vsnprintf -#define RETSIGTYPE void #else /* _WIN32 */ @@ -217,12 +257,20 @@ typedef char* caddr_t; #include #include -#ifdef TIME_WITH_SYS_TIME #include -#endif #include +/* + * Assume all UN*Xes have strtoll(), and use it for strtoint64_t(). + */ +#define strtoint64_t strtoll + +/* + * Assume LL works. + */ +#define INT64_T_CONSTANT(constant) (constant##LL) + #endif /* _WIN32 */ #ifndef HAVE___ATTRIBUTE__ @@ -287,8 +335,8 @@ typedef char* caddr_t; * an 80386, so, for example, it avoids the bswap instruction added in * the 80486. * - * (We don't use them on OS X; Apple provides their own, which *doesn't* - * avoid the bswap instruction, as OS X only supports machines that + * (We don't use them on macOS; Apple provides their own, which *doesn't* + * avoid the bswap instruction, as macOS only supports machines that * have it.) */ #if defined(__GNUC__) && defined(__i386__) && !defined(__APPLE__) && !defined(__ntohl) @@ -373,7 +421,20 @@ struct in6_addr { #define DIAG_JOINSTR(x,y) XSTRINGIFY(x ## y) #define DIAG_DO_PRAGMA(x) _Pragma (#x) -#if defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402 +/* + * The current clang compilers also define __GNUC__ and __GNUC_MINOR__ + * thus we need to test the clang case before the GCC one + */ +#if defined(__clang__) +# if (__clang_major__ * 100) + __clang_minor__ >= 208 +# define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(clang diagnostic x) +# define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x)) +# define DIAG_ON(x) DIAG_PRAGMA(pop) +# else +# define DIAG_OFF(x) +# define DIAG_ON(x) +# endif +#elif defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402 # define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(GCC diagnostic x) # if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406 # define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x)) @@ -382,15 +443,20 @@ struct in6_addr { # define DIAG_OFF(x) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x)) # define DIAG_ON(x) DIAG_PRAGMA(warning DIAG_JOINSTR(-W,x)) # endif -#elif defined(__clang__) && ((__clang_major__ * 100) + __clang_minor__ >= 208) -# define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(clang diagnostic x) -# define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x)) -# define DIAG_ON(x) DIAG_PRAGMA(pop) #else # define DIAG_OFF(x) # define DIAG_ON(x) #endif +/* Use for clang specific warnings */ +#ifdef __clang__ +# define DIAG_OFF_CLANG(x) DIAG_OFF(x) +# define DIAG_ON_CLANG(x) DIAG_ON(x) +#else +# define DIAG_OFF_CLANG(x) +# define DIAG_ON_CLANG(x) +#endif + /* * For dealing with APIs which are only deprecated in OSX (like the OpenSSL API) */ @@ -411,13 +477,6 @@ struct in6_addr { */ #include "funcattrs.h" -#ifndef min -#define min(a,b) ((a)>(b)?(b):(a)) -#endif -#ifndef max -#define max(a,b) ((b)>(a)?(b):(a)) -#endif - #ifdef __ATTRIBUTE___FALLTHROUGH_OK # define ND_FALL_THROUGH __attribute__ ((fallthrough)) #else