]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - compat/types.h
SourceFormat Enforcement
[thirdparty/squid.git] / compat / types.h
index 66adb85e186b0efcd220583e21ae937a3369f25d..8149f6211b71a4190d21695aa306bb93ca5184c9 100644 (file)
@@ -1,52 +1,15 @@
-#ifndef SQUID_CONFIG_H
-#include "config.h"
-#endif
-
 /*
- * * * * * * * * Legal stuff * * * * * * *
- *
- * (C) 2000 Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- * SQUID Web Proxy Cache          http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- *  Squid is the result of efforts by numerous individuals from
- *  the Internet community; see the CONTRIBUTORS file for full
- *  details.   Many organizations have provided support for Squid's
- *  development; see the SPONSORS file for full details.  Squid is
- *  Copyrighted (C) 2001 by the Regents of the University of
- *  California; see the COPYRIGHT file for full details.  Squid
- *  incorporates software developed and/or copyrighted by other
- *  sources; see the CREDITS file for full details.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
- *
- * * * * * * * * Declaration of intents * * * * * * *
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
  *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_TYPES_H
+#define SQUID_TYPES_H
+
+/*
  * Here are defined several known-width types, obtained via autoconf
  * from system locations or various attempts. This is just a convenience
  * header to include which takes care of proper preprocessor stuff
@@ -55,9 +18,6 @@
  * not include directly.
  */
 
-#ifndef SQUID_TYPES_H
-#define SQUID_TYPES_H
-
 /* This should be in synch with what we have in acinclude.m4 */
 #if HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #include <netinet/in_systm.h>
 #endif
 
+#if __cplusplus && HAVE_TR1_RANDOM
+#if !HAVE_STD_UNIFORM_INT_DISTRIBUTION && !HAVE_STD_UNIFORM_REAL_DISTRIBUTION
+#include <tr1/random>
+#endif
+#endif
 
 /******************************************************/
 /* Typedefs for missing entries on a system           */
 /******************************************************/
 
+/*
+ * Ensure that standard type limits are defined for use
+ */
+#if __cplusplus >= 201103L
+#include <cstdint>
+#elif HAVE_STDINT_H
+#include <stdint.h>
+#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
  * "%lx" instead of "%llx"
  */
 #ifndef PRId64
-#ifdef _SQUID_MSWIN_           /* Windows native port using MSVCRT */
+#if _SQUID_WINDOWS_
 #define PRId64 "I64d"
 #elif SIZEOF_INT64_T > SIZEOF_LONG
 #define PRId64 "lld"
 #endif
 
 #ifndef PRIu64
-#ifdef _SQUID_MSWIN_           /* Windows native port using MSVCRT */
+#if _SQUID_WINDOWS_
 #define PRIu64 "I64u"
 #elif SIZEOF_INT64_T > SIZEOF_LONG
 #define PRIu64 "llu"
 #endif
 #endif
 
-/* int64_t */
-#ifndef HAVE_INT64_T
-#if HAVE___INT64
-typedef __int64 int64_t;
-#elif HAVE_LONG && SIZEOF_LONG == 8
-typedef long int64_t;
-#elif HAVE_LONG_LONG && SIZEOF_LONG_LONG == 8
-typedef long long int64_t;
-#else
-#error NO 64 bit signed type available
-#endif
-#endif
-
-/* uint64_t */
-#if !HAVE_UINT64_T
-#if HAVE_U_INT64_T
-typedef u_int64_t uint64_t;
-#define HAVE_UINT64_T 1
-#elif HAVE_INT64_T
-typedef unsigned int64_t uint64_t;
-#define HAVE_UINT64_T 1
-#endif /* HAVE_U_INT64_T */
-#endif /* HAVE_UINT64_T */
-
-/* int32_t */
-#ifndef HAVE_INT32_T
-#if HAVE_INT && SIZEOF_INT == 4
-typedef int int32_t;
-#elif HAVE_LONG && SIZEOF_LONG == 4
-typedef long int32_t;
-#else
-#error NO 32 bit signed type available
-#endif
-#endif
-
-/* uint32_t */
-#if !HAVE_UINT32_T
-#if HAVE_U_INT32_T
-typedef u_int32_t uint32_t;
-#define HAVE_UINT32_T 1
-#elif HAVE_INT32_T
-typedef unsigned int32_t uint32_t;
-#define HAVE_UINT32_T 1
-#endif /* HAVE_U_INT32_T */
-#endif /* HAVE_UINT32_T */
-
-/* int16_t */
-#ifndef HAVE_INT16_T
-#if HAVE_SHORT && SIZEOF_SHORT == 2
-typedef short int16_t;
-#elif HAVE_INT && SIZEOF_INT == 2
-typedef int int16_t;
-#else
-#error NO 16 bit signed type available
-#endif
-#endif
-
-/* uint16_t */
-#if !HAVE_UINT16_T
-#if HAVE_U_INT16_T
-typedef u_int16_t uint16_t;
-#define HAVE_UINT16_T 1
-#elif HAVE_INT16_T
-typedef unsigned int16_t uint16_t;
-#define HAVE_UINT16_T 1
-#endif /* HAVE_U_INT16_T */
-#endif /* HAVE_UINT16_T */
-
-/* int8_t */
-#ifndef HAVE_INT8_T
-#if HAVE_CHAR && SIZEOF_CHAR == 1
-typedef char int8_t;
+#ifndef PRIX64
+#if _SQUID_WINDOWS_
+#define PRIX64 "I64X"
+#elif SIZEOF_INT64_T > SIZEOF_LONG
+#define PRIX64 "llX"
 #else
-#error NO 8 bit signed type available
+#define PRIX64 "lX"
 #endif
 #endif
 
-/* uint8_t */
-#if !HAVE_UINT8_T
-#if HAVE_U_INT8_T
-typedef u_int8_t uint8_t;
-#define HAVE_UINT8_T 1
-#elif HAVE_INT8_T
-typedef unsigned int8_t uint8_t;
-#define HAVE_UINT8_T 1
-#endif /* HAVE_U_INT8_T */
-#endif /* HAVE_UINT8_T */
-
-#ifndef HAVE_PID_T
-#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
-typedef long pid_t;
+#ifndef PRIuSIZE
+// NP: configure checks for support of %zu and defines where possible
+#if SIZEOF_SIZE_T == 4 && _SQUID_MINGW_
+#define PRIuSIZE "I32u"
+#elif SIZEOF_SIZE_T == 4
+#define PRIuSIZE "u"
+#elif SIZEOF_SIZE_T == 8 && _SQUID_MINGW_
+#define PRIuSIZE "I64u"
+#elif SIZEOF_SIZE_T == 8
+#define PRIuSIZE "lu"
 #else
-typedef int pid_t;
-#endif
-#endif
-
-#ifndef HAVE_SIZE_T
-typedef unsigned int size_t;
-#endif
-
-#ifndef HAVE_SSIZE_T
-typedef int ssize_t;
-#endif
-
-#ifndef HAVE_OFF_T
-#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
-#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
-typedef int64_t off_t;
-#else
-typedef long off_t;
-#endif
-#else
-typedef int off_t;
-#endif
+#error size_t is not 32-bit or 64-bit
 #endif
+#endif /* PRIuSIZE */
 
 #ifndef HAVE_MODE_T
 typedef unsigned short mode_t;
@@ -248,4 +162,24 @@ typedef int socklen_t;
 typedef long mtyp_t;
 #endif
 
+#ifndef NULL
+#define NULL 0
+#endif
+
+/***********************************************************/
+/* uniform_int_distribution backward compatibility wrapper */
+/***********************************************************/
+#if HAVE_STD_UNIFORM_INT_DISTRIBUTION
+#define xuniform_int_distribution std::uniform_int_distribution
+#else
+#define xuniform_int_distribution std::tr1::uniform_int
+#endif
+
+#if HAVE_STD_UNIFORM_REAL_DISTRIBUTION
+#define xuniform_real_distribution std::uniform_real_distribution
+#else
+#define xuniform_real_distribution std::tr1::uniform_real
+#endif
+
 #endif /* SQUID_TYPES_H */
+