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