1 /* 2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors 3 * 4 * Squid software is distributed under GPLv2+ license and includes 5 * contributions from numerous individuals and organizations. 6 * Please see the COPYING and CONTRIBUTORS files for details. 7 */ 8 9 #ifndef SQUID_TYPES_H 10 #define SQUID_TYPES_H 11 12 /* 13 * Here are defined several known-width types, obtained via autoconf 14 * from system locations or various attempts. This is just a convenience 15 * header to include which takes care of proper preprocessor stuff 16 * 17 * This file is only intended to be included via compat/compat.h, do 18 * not include directly. 19 */ 20 21 /* This should be in synch with what we have in acinclude.m4 */ 22 #if HAVE_SYS_TYPES_H 23 #include <sys/types.h> 24 #endif 25 #if HAVE_LINUX_TYPES_H 26 #include <linux/types.h> 27 #endif 28 #if HAVE_STDLIB_H 29 #include <stdlib.h> 30 #endif 31 #if HAVE_STDDEF_H 32 #include <stddef.h> 33 #endif 34 #if HAVE_INTTYPES_H 35 #include <inttypes.h> 36 #endif 37 #if HAVE_SYS_BITYPES_H 38 #include <sys/bitypes.h> 39 #endif 40 #if HAVE_SYS_SELECT_H 41 #include <sys/select.h> 42 #endif 43 #if HAVE_NETINET_IN_SYSTM_H 44 /* Several OS require types declared by in_systm.h without including it themselves. */ 45 #include <netinet/in_systm.h> 46 #endif 47 48 #if __cplusplus && HAVE_TR1_RANDOM 49 #if !HAVE_STD_UNIFORM_INT_DISTRIBUTION && !HAVE_STD_UNIFORM_REAL_DISTRIBUTION 50 #include <tr1/random> 51 #endif 52 #endif 53 54 /******************************************************/ 55 /* Typedefs for missing entries on a system */ 56 /******************************************************/ 57 58 /* 59 * Ensure that standard type limits are defined for use 60 */ 61 #if __cplusplus >= 201103L 62 #include <cstdint> 63 #elif HAVE_STDINT_H 64 #include <stdint.h> 65 #endif 66 67 /* explicit bit sizes */ 68 #if !defined(UINT32_MIN) 69 #define UINT32_MIN 0x00000000L 70 #endif 71 #if !defined(UINT32_MAX) 72 #define UINT32_MAX 0xFFFFFFFFL 73 #endif 74 75 #if !defined(INT_MAX) 76 #define INT_MAX 0x7FFFFFFFL // hack but a safe bet (32-bit signed integer) 77 #endif 78 79 #if !defined(INT64_MIN) 80 /* Native 64 bit system without strtoll() */ 81 #if defined(LONG_MIN) && (SIZEOF_LONG == 8) 82 #define INT64_MIN LONG_MIN 83 #else 84 /* 32 bit system */ 85 #define INT64_MIN (-9223372036854775807LL-1LL) 86 #endif 87 #endif 88 89 #if !defined(INT64_MAX) 90 /* Native 64 bit system without strtoll() */ 91 #if defined(LONG_MAX) && (SIZEOF_LONG == 8) 92 #define INT64_MAX LONG_MAX 93 #else 94 /* 32 bit system */ 95 #define INT64_MAX 9223372036854775807LL 96 #endif 97 #endif 98 99 /* 100 * ISO C99 Standard printf() macros for 64 bit integers 101 * On some 64 bit platform, HP Tru64 is one, for printf must be used 102 * "%lx" instead of "%llx" 103 */ 104 #ifndef PRId64 105 #if _SQUID_WINDOWS_ 106 #define PRId64 "I64d" 107 #elif SIZEOF_INT64_T > SIZEOF_LONG 108 #define PRId64 "lld" 109 #else 110 #define PRId64 "ld" 111 #endif 112 #endif 113 114 #ifndef PRIu64 115 #if _SQUID_WINDOWS_ 116 #define PRIu64 "I64u" 117 #elif SIZEOF_INT64_T > SIZEOF_LONG 118 #define PRIu64 "llu" 119 #else 120 #define PRIu64 "lu" 121 #endif 122 #endif 123 124 #ifndef PRIX64 125 #if _SQUID_WINDOWS_ 126 #define PRIX64 "I64X" 127 #elif SIZEOF_INT64_T > SIZEOF_LONG 128 #define PRIX64 "llX" 129 #else 130 #define PRIX64 "lX" 131 #endif 132 #endif 133 134 #ifndef PRIuSIZE 135 // NP: configure checks for support of %zu and defines where possible 136 #if SIZEOF_SIZE_T == 4 && _SQUID_MINGW_ 137 #define PRIuSIZE "I32u" 138 #elif SIZEOF_SIZE_T == 4 139 #define PRIuSIZE "u" 140 #elif SIZEOF_SIZE_T == 8 && _SQUID_MINGW_ 141 #define PRIuSIZE "I64u" 142 #elif SIZEOF_SIZE_T == 8 143 #define PRIuSIZE "lu" 144 #else 145 #error size_t is not 32-bit or 64-bit 146 #endif 147 #endif /* PRIuSIZE */ 148 149 #ifndef HAVE_MODE_T 150 typedef unsigned short mode_t; 151 #endif 152 153 #ifndef HAVE_FD_MASK 154 typedef unsigned long fd_mask; 155 #endif 156 157 #ifndef HAVE_SOCKLEN_T 158 typedef int socklen_t; 159 #endif 160 161 #ifndef HAVE_MTYP_T 162 typedef long mtyp_t; 163 #endif 164 165 #ifndef NULL 166 #define NULL 0 167 #endif 168 169 /***********************************************************/ 170 /* uniform_int_distribution backward compatibility wrapper */ 171 /***********************************************************/ 172 #if HAVE_STD_UNIFORM_INT_DISTRIBUTION 173 #define xuniform_int_distribution std::uniform_int_distribution 174 #else 175 #define xuniform_int_distribution std::tr1::uniform_int 176 #endif 177 178 #if HAVE_STD_UNIFORM_REAL_DISTRIBUTION 179 #define xuniform_real_distribution std::uniform_real_distribution 180 #else 181 #define xuniform_real_distribution std::tr1::uniform_real 182 #endif 183 184 #endif /* SQUID_TYPES_H */ 185 186