From: Amos Jeffries Date: Wed, 22 Apr 2015 13:32:56 +0000 (-0700) Subject: Portability: Add hacks to define C++11 explicit N-bit type limits X-Git-Tag: merge-candidate-3-v1~161 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2c4db06c5fada3ea391701cca32997ccf2d8295;p=thirdparty%2Fsquid.git Portability: Add hacks to define C++11 explicit N-bit type limits Add cstdint and stdint.h to libcompat headers and ensure that type limits used by Squid are always available. Mostly this involves shuffling existing hacks into the compat headers but the UINT32_* limits are new. --- diff --git a/compat/types.h b/compat/types.h index 3833bfa285..50211aa310 100644 --- a/compat/types.h +++ b/compat/types.h @@ -49,6 +49,47 @@ /* Typedefs for missing entries on a system */ /******************************************************/ +/* + * Ensure that standard type limits are defined for use + */ +#if __cplusplus >= 201103L +#include +#elif HAVE_STDINT_H +#include +#endif + +/* explicit bit sizes */ +#if !defined(UINT32_MIN) +#define UINT32_MIN 0x00000000L +#endif +#if !defined(UINT32_MAX) +#define UINT32_MAX 0xFFFFFFFFL +#endif + +#if !defined(INT_MAX) +#define INT_MAX 0x7FFFFFFFL // hack but a safe bet (32-bit signed integer) +#endif + +#if !defined(INT64_MIN) +/* Native 64 bit system without strtoll() */ +#if defined(LONG_MIN) && (SIZEOF_LONG == 8) +#define INT64_MIN LONG_MIN +#else +/* 32 bit system */ +#define INT64_MIN (-9223372036854775807LL-1LL) +#endif +#endif + +#if !defined(INT64_MAX) +/* Native 64 bit system without strtoll() */ +#if defined(LONG_MAX) && (SIZEOF_LONG == 8) +#define INT64_MAX LONG_MAX +#else +/* 32 bit system */ +#define INT64_MAX 9223372036854775807LL +#endif +#endif + /* * ISO C99 Standard printf() macros for 64 bit integers * On some 64 bit platform, HP Tru64 is one, for printf must be used diff --git a/helpers/ntlm_auth/fake/ntlm_fake_auth.cc b/helpers/ntlm_auth/fake/ntlm_fake_auth.cc index 38b0f7729d..026484fc21 100644 --- a/helpers/ntlm_auth/fake/ntlm_fake_auth.cc +++ b/helpers/ntlm_auth/fake/ntlm_fake_auth.cc @@ -50,12 +50,6 @@ #if HAVE_GETOPT_H #include #endif -#if HAVE_STDINT_H -#include -#endif -#if HAVE_INTTYPES_H -#include -#endif /* A couple of harmless helper macros */ #define SEND(X) {debug("sending '%s' to squid\n",X); printf(X "\n");} diff --git a/src/String.cci b/src/String.cci index fa3fa78aef..ddc6595218 100644 --- a/src/String.cci +++ b/src/String.cci @@ -10,14 +10,6 @@ #include -#if HAVE_STDINT_H -#include -#else /* HAVE_STDINT_H */ -#ifndef INT_MAX -#define INT_MAX 1<<31 //hack but a safe bet -#endif /* INT_MAX */ -#endif /* HAVE_STDINT_H */ - String::String() : size_(0), len_(0), buf_(NULL) { #if DEBUGSTRINGS diff --git a/src/base/Lock.h b/src/base/Lock.h index f081cf5cf4..8a995e59ca 100644 --- a/src/base/Lock.h +++ b/src/base/Lock.h @@ -9,12 +9,6 @@ #ifndef SQUID_SRC_BASE_LOCK_H #define SQUID_SRC_BASE_LOCK_H -#if __cplusplus >= 201103L -#include -#else -#include -#endif - /** * This class provides a tracking counter and presents * lock(), unlock() and LockCount() accessors. diff --git a/src/parser/Tokenizer.cc b/src/parser/Tokenizer.cc index 49fac70f79..68fcb7cafc 100644 --- a/src/parser/Tokenizer.cc +++ b/src/parser/Tokenizer.cc @@ -16,28 +16,6 @@ #if HAVE_CTYPE_H #include #endif -#if HAVE_STDINT_H -#include -#endif -#ifndef INT64_MIN -/* Native 64 bit system without strtoll() */ -#if defined(LONG_MIN) && (SIZEOF_LONG == 8) -#define INT64_MIN LONG_MIN -#else -/* 32 bit system */ -#define INT64_MIN (-9223372036854775807LL-1LL) -#endif -#endif - -#ifndef INT64_MAX -/* Native 64 bit system without strtoll() */ -#if defined(LONG_MAX) && (SIZEOF_LONG == 8) -#define INT64_MAX LONG_MAX -#else -/* 32 bit system */ -#define INT64_MAX 9223372036854775807LL -#endif -#endif /// convenience method: consumes up to n bytes, counts, and returns them SBuf