1 #ifndef LI_FIRST_H 2 #define LI_FIRST_H 3 4 #ifdef HAVE_CONFIG_H 5 # include "config.h" 6 #else 7 # ifndef _GNU_SOURCE 8 # define _GNU_SOURCE 9 # endif 10 #endif 11 12 #ifndef _DEFAULT_SOURCE 13 #define _DEFAULT_SOURCE 14 #endif 15 16 #if defined(__APPLE__) && defined(__MACH__) 17 #ifndef _DARWIN_C_SOURCE 18 #define _DARWIN_C_SOURCE 19 #endif 20 #endif 21 22 #ifndef __STDC_WANT_LIB_EXT1__ 23 #define __STDC_WANT_LIB_EXT1__ 1 24 #endif 25 26 #ifdef __COVERITY__ 27 #define _Float128 long double 28 #define _Float64x long double 29 #define _Float64 double 30 #define _Float32x double 31 #define _Float32 float 32 #endif 33 34 /* enable glibc Y2038 64-bit time_t (where available on 32-bit systems) */ 35 #ifdef _ILP32 36 #ifndef _TIME_BITS 37 #define _TIME_BITS 64 38 #endif 39 #ifndef _FILE_OFFSET_BITS 40 #define _FILE_OFFSET_BITS 64 41 #endif 42 #endif 43 44 45 #include <sys/types.h> 46 #include <stddef.h> 47 48 #ifdef __has_include 49 #if __has_include(<sys/cdefs.h>) 50 #include <sys/cdefs.h> 51 #endif 52 #endif 53 54 #ifndef __BEGIN_DECLS 55 #ifdef __cplusplus 56 #define __BEGIN_DECLS extern "C" { 57 #else 58 #define __BEGIN_DECLS 59 #endif 60 #endif 61 62 #ifndef __END_DECLS 63 #ifdef __cplusplus 64 #define __END_DECLS } 65 #else 66 #define __END_DECLS 67 #endif 68 #endif 69 70 #if defined HAVE_STDINT_H 71 # include <stdint.h> 72 #elif defined HAVE_INTTYPES_H 73 # include <inttypes.h> 74 #endif 75 76 77 /* solaris and NetBSD 1.3.x again */ 78 #if (!defined(HAVE_STDINT_H)) && (!defined(HAVE_INTTYPES_H)) && (!defined(uint32_t)) 79 # define uint32_t u_int32_t 80 #endif 81 82 83 #include <limits.h> 84 85 #ifndef SIZE_MAX 86 # ifdef SIZE_T_MAX 87 # define SIZE_MAX SIZE_T_MAX 88 # else 89 # define SIZE_MAX (~(size_t)0u) 90 # endif 91 #endif 92 93 #ifndef SSIZE_MAX 94 # define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1)) 95 #endif 96 97 98 /* TODO: would be more accurate to create build-system test for sizeof(time_t)*/ 99 #ifndef HAS_TIME_BITS64 100 #if defined(_LP64) || defined(__LP64__) || defined(_WIN64) 101 #define HAS_TIME_BITS64 1 102 #elif defined(__TIMESIZE) 103 #if __TIMESIZE == 64 104 #define HAS_TIME_BITS64 1 105 #elif defined(__USE_TIME_BITS64) 106 #define HAS_TIME_BITS64 1 107 #else 108 #define HAS_TIME_BITS64 0 109 #endif 110 #elif defined(_WIN32) 111 #ifndef _USE_32BIT_TIME_T 112 #define HAS_TIME_BITS64 1 113 #else 114 #define HAS_TIME_BITS64 0 115 #endif 116 #elif defined(_ILP32) \ 117 && !defined(__USE_TIME_BITS64) \ 118 && !defined(__NetBSD__) && !defined(__OpenBSD__) \ 119 && (!defined(__FreeBSD__) || !defined(__i386__)) \ 120 && !(defined(__APPLE__) && defined(__MACH__)) 121 #define HAS_TIME_BITS64 0 122 #else 123 #define HAS_TIME_BITS64 1 124 #endif 125 #endif 126 127 /* non-standard types created for lighttpd for Y2038 problem 128 * reference: https://en.wikipedia.org/wiki/Year_2038_problem */ 129 #if HAS_TIME_BITS64 130 typedef time_t unix_time64_t; 131 typedef struct timespec unix_timespec64_t; 132 #define TIME64_CAST(t) (t) 133 #else /* !HAS_TIME_BITS64 */ 134 typedef int64_t unix_time64_t; 135 struct unix_timespec64 { 136 unix_time64_t tv_sec; /* seconds */ 137 long tv_nsec; /* nanoseconds */ 138 }; 139 typedef struct unix_timespec64 unix_timespec64_t; 140 #define TIME64_CAST(t) ((unix_time64_t)(uint32_t)(t)) 141 #endif /* !HAS_TIME_BITS64 */ 142 143 144 #define UNUSED(x) ( (void)(x) ) 145 146 147 #ifndef __has_attribute /* clang */ 148 #define __has_attribute(x) 0 149 #endif 150 151 #ifndef __has_builtin /* clang */ 152 #define __has_builtin(x) 0 153 #endif 154 155 #ifdef __GNUC__ 156 #ifndef __GNUC_PREREQ 157 # ifdef __GNUC_PREREQ__ 158 # define __GNUC_PREREQ __GNUC_PREREQ__ 159 # elif defined __GNUC__ && defined __GNUC_MINOR__ 160 # define __GNUC_PREREQ(maj, min) \ 161 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) 162 # else 163 # define __GNUC_PREREQ(maj, min) 0 164 # endif 165 #endif 166 #else 167 #define __GNUC_PREREQ(maj,min) 0 168 #endif 169 170 #ifndef __builtin_expect 171 #if !__has_builtin(__builtin_expect) \ 172 && !__GNUC_PREREQ(2,96) 173 #define __builtin_expect(x,y) (x) 174 #endif 175 #endif 176 177 #ifndef __attribute_noinline__ 178 #if __has_attribute(noinline) \ 179 || __GNUC_PREREQ(3,1) 180 #define __attribute_noinline__ __attribute__((__noinline__)) 181 #else 182 #define __attribute_noinline__ 183 #endif 184 #endif 185 186 #ifndef __attribute_cold__ 187 #if __has_attribute(cold) \ 188 || __GNUC_PREREQ(4,3) 189 #define __attribute_cold__ __attribute__((__cold__)) 190 #else 191 #define __attribute_cold__ 192 #endif 193 #endif 194 195 #ifndef __attribute_hot__ 196 #if __has_attribute(hot) \ 197 || __GNUC_PREREQ(4,3) 198 #define __attribute_hot__ __attribute__((__hot__)) 199 #else 200 #define __attribute_hot__ 201 #endif 202 #endif 203 204 #ifndef __attribute_noreturn__ 205 #if __has_attribute(noreturn) \ 206 || __GNUC_PREREQ(2,5) 207 #define __attribute_noreturn__ __attribute__((__noreturn__)) 208 #else 209 #define __attribute_noreturn__ 210 #endif 211 #endif 212 213 #ifndef __attribute_fallthrough__ 214 #if __has_attribute(fallthrough) \ 215 || __GNUC_PREREQ(7,0) 216 #define __attribute_fallthrough__ __attribute__((__fallthrough__)); 217 #else 218 #define __attribute_fallthrough__ /* fall through */ 219 #endif 220 #endif 221 222 #ifndef __attribute_format__ 223 #if __has_attribute(format) \ 224 || __GNUC_PREREQ(2,95) /*(maybe earlier gcc, too)*/ 225 #define __attribute_format__(x) __attribute__((__format__ x)) 226 #else 227 #define __attribute_format__(x) 228 #endif 229 #endif 230 231 #ifndef __attribute_const__ 232 #if __has_attribute(const) \ 233 || __GNUC_PREREQ(2,5) 234 #define __attribute_const__ __attribute__((__const__)) 235 #else 236 #define __attribute_const__ 237 #endif 238 #endif 239 240 #ifndef __attribute_pure__ 241 #if __has_attribute(pure) \ 242 || __GNUC_PREREQ(2,96) 243 #define __attribute_pure__ __attribute__((__pure__)) 244 #else 245 #define __attribute_pure__ 246 #endif 247 #endif 248 249 #ifndef __attribute_returns_nonnull__ 250 #if __has_attribute(returns_nonnull) \ 251 || __GNUC_PREREQ(4,9) 252 #define __attribute_returns_nonnull__ __attribute__((__returns_nonnull__)) 253 #else 254 #define __attribute_returns_nonnull__ 255 #endif 256 #endif 257 258 #ifndef __attribute_nonnull__ 259 #if __has_attribute(nonnull) \ 260 || __GNUC_PREREQ(3,3) 261 #define __attribute_nonnull__(params) __attribute__((__nonnull__ params)) 262 #else 263 #define __attribute_nonnull__(params) 264 #endif 265 #endif 266 267 #ifndef __attribute_malloc__ 268 #if __has_attribute(malloc) \ 269 || __GNUC_PREREQ(2,96) 270 #define __attribute_malloc__ __attribute__((__malloc__)) 271 #elif defined(_MSC_VER) 272 #undef restrict 273 #define __attribute_malloc__ __declspec(restrict) 274 #define restrict __restrict 275 #else 276 #define __attribute_malloc__ 277 #endif 278 #endif 279 280 #ifndef __attribute_unused__ 281 #if __has_attribute(unused) \ 282 || __GNUC_PREREQ(2,95) 283 #define __attribute_unused__ __attribute__((__unused__)) 284 #else 285 #define __attribute_unused__ 286 #endif 287 #endif 288 289 290 #endif 291