1 #if defined(__cplusplus) && !defined(__clang__) 2 #define __C11_ATOMIC(t) t 3 #else 4 #define __C11_ATOMIC(t) _Atomic(t) 5 #endif 6 7 #if defined(__NEED_uint8_t) && !defined(__DEFINED_uint8_t) 8 typedef __UINT8_TYPE__ uint8_t; 9 #define __DEFINED_uint8_t 10 #endif 11 12 #if defined(__NEED_uint16_t) && !defined(__DEFINED_uint16_t) 13 typedef __UINT16_TYPE__ uint16_t; 14 #define __DEFINED_uint16_t 15 #endif 16 17 #if defined(__NEED_uint32_t) && !defined(__DEFINED_uint32_t) 18 typedef __UINT32_TYPE__ uint32_t; 19 #define __DEFINED_uint32_t 20 #endif 21 22 #if defined(__NEED_uint64_t) && !defined(__DEFINED_uint64_t) 23 typedef __UINT64_TYPE__ uint64_t; 24 #define __DEFINED_uint64_t 25 #endif 26 27 #if defined(__NEED_int8_t) && !defined(__DEFINED_int8_t) 28 typedef __INT8_TYPE__ int8_t; 29 #define __DEFINED_int8_t 30 #endif 31 32 #if defined(__NEED_int16_t) && !defined(__DEFINED_int16_t) 33 typedef __INT16_TYPE__ int16_t; 34 #define __DEFINED_int16_t 35 #endif 36 37 #if defined(__NEED_int32_t) && !defined(__DEFINED_int32_t) 38 typedef __INT32_TYPE__ int32_t; 39 #define __DEFINED_int32_t 40 #endif 41 42 #if defined(__NEED_int64_t) && !defined(__DEFINED_int64_t) 43 typedef __INT64_TYPE__ int64_t; 44 #define __DEFINED_int64_t 45 #endif 46 47 #if defined(__NEED_uint_least8_t) && !defined(__DEFINED_uint_least8_t) 48 typedef __UINT_LEAST8_TYPE__ uint_least8_t; 49 #define __DEFINED_uint_least8_t 50 #endif 51 52 #if defined(__NEED_uint_least16_t) && !defined(__DEFINED_uint_least16_t) 53 typedef __UINT_LEAST16_TYPE__ uint_least16_t; 54 #define __DEFINED_uint_least16_t 55 #endif 56 57 #if defined(__NEED_uint_least32_t) && !defined(__DEFINED_uint_least32_t) 58 typedef __UINT_LEAST32_TYPE__ uint_least32_t; 59 #define __DEFINED_uint_least32_t 60 #endif 61 62 #if defined(__NEED_uint_least64_t) && !defined(__DEFINED_uint_least64_t) 63 typedef __UINT_LEAST64_TYPE__ uint_least64_t; 64 #define __DEFINED_uint_least64_t 65 #endif 66 67 #if defined(__NEED_int_least8_t) && !defined(__DEFINED_int_least8_t) 68 typedef __INT_LEAST8_TYPE__ int_least8_t; 69 #define __DEFINED_int_least8_t 70 #endif 71 72 #if defined(__NEED_int_least16_t) && !defined(__DEFINED_int_least16_t) 73 typedef __INT_LEAST16_TYPE__ int_least16_t; 74 #define __DEFINED_int_least16_t 75 #endif 76 77 #if defined(__NEED_int_least32_t) && !defined(__DEFINED_int_least32_t) 78 typedef __INT_LEAST32_TYPE__ int_least32_t; 79 #define __DEFINED_int_least32_t 80 #endif 81 82 #if defined(__NEED_int_least64_t) && !defined(__DEFINED_int_least64_t) 83 typedef __INT_LEAST64_TYPE__ int_least64_t; 84 #define __DEFINED_int_least64_t 85 #endif 86 87 #if defined(__NEED_uint_fast8_t) && !defined(__DEFINED_uint_fast8_t) 88 typedef __UINT_FAST8_TYPE__ uint_fast8_t; 89 #define __DEFINED_uint_fast8_t 90 #endif 91 92 #if defined(__NEED_uint_fast16_t) && !defined(__DEFINED_uint_fast16_t) 93 typedef __UINT_FAST16_TYPE__ uint_fast16_t; 94 #define __DEFINED_uint_fast16_t 95 #endif 96 97 #if defined(__NEED_uint_fast32_t) && !defined(__DEFINED_uint_fast32_t) 98 typedef __UINT_FAST32_TYPE__ uint_fast32_t; 99 #define __DEFINED_uint_fast32_t 100 #endif 101 102 #if defined(__NEED_uint_fast64_t) && !defined(__DEFINED_uint_fast64_t) 103 typedef __UINT_FAST64_TYPE__ uint_fast64_t; 104 #define __DEFINED_uint_fast64_t 105 #endif 106 107 #if defined(__NEED_int_fast8_t) && !defined(__DEFINED_int_fast8_t) 108 typedef __INT_FAST8_TYPE__ int_fast8_t; 109 #define __DEFINED_int_fast8_t 110 #endif 111 112 #if defined(__NEED_int_fast16_t) && !defined(__DEFINED_int_fast16_t) 113 typedef __INT_FAST16_TYPE__ int_fast16_t; 114 #define __DEFINED_int_fast16_t 115 #endif 116 117 #if defined(__NEED_int_fast32_t) && !defined(__DEFINED_int_fast32_t) 118 typedef __INT_FAST32_TYPE__ int_fast32_t; 119 #define __DEFINED_int_fast32_t 120 #endif 121 122 #if defined(__NEED_int_fast64_t) && !defined(__DEFINED_int_fast64_t) 123 typedef __INT_FAST64_TYPE__ int_fast64_t; 124 #define __DEFINED_int_fast64_t 125 #endif 126 127 #if defined(__NEED_intptr_t) && !defined(__DEFINED_intptr_t) 128 typedef __INTPTR_TYPE__ intptr_t; 129 #define __DEFINED_intptr_t 130 #endif 131 132 #if defined(__NEED_uintptr_t) && !defined(__DEFINED_uintptr_t) 133 typedef __UINTPTR_TYPE__ uintptr_t; 134 #define __DEFINED_uintptr_t 135 #endif 136 137 #if defined(__NEED_intmax_t) && !defined(__DEFINED_intmax_t) 138 typedef __INTMAX_TYPE__ intmax_t; 139 #define __DEFINED_intmax_t 140 #endif 141 142 #if defined(__NEED_uintmax_t) && !defined(__DEFINED_uintmax_t) 143 typedef __UINTMAX_TYPE__ uintmax_t; 144 #define __DEFINED_uintmax_t 145 #endif 146 147 #ifndef __cplusplus 148 #if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t) 149 typedef __WCHAR_TYPE__ wchar_t; 150 #define __DEFINED_wchar_t 151 #endif 152 #endif 153 154 #if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t) 155 typedef unsigned wint_t; 156 #define __DEFINED_wint_t 157 #endif 158 159 #if defined(__NEED_wctype_t) && !defined(__DEFINED_wctype_t) 160 typedef unsigned long wctype_t; 161 #define __DEFINED_wctype_t 162 #endif 163 164 #if defined(__NEED_size_t) && !defined(__DEFINED_size_t) 165 typedef __SIZE_TYPE__ size_t; 166 #define __DEFINED_size_t 167 #endif 168 169 #if defined(__NEED_ptrdiff_t) && !defined(__DEFINED_ptrdiff_t) 170 typedef __PTRDIFF_TYPE__ ptrdiff_t; 171 #define __DEFINED_ptrdiff_t 172 #endif 173 174 #if defined(__NEED_va_list) && !defined(__DEFINED_va_list) 175 typedef __builtin_va_list va_list; 176 #define __DEFINED_va_list 177 #endif 178 179 #if defined(__NEED___isoc_va_list) && !defined(__DEFINED___isoc_va_list) 180 typedef __builtin_va_list __isoc_va_list; 181 #define __DEFINED___isoc_va_list 182 #endif 183 184 #if defined(__NEED_ssize_t) && !defined(__DEFINED_ssize_t) 185 typedef long ssize_t; 186 #define __DEFINED_ssize_t 187 #endif 188 189 #if defined(__NEED_time_t) && !defined(__DEFINED_time_t) 190 typedef long time_t; 191 #define __DEFINED_time_t 192 #endif 193 194 #if defined(__NEED_max_align_t) && !defined(__DEFINED_max_align_t) 195 typedef struct { 196 long long __ll; 197 long double __ld; 198 } max_align_t; 199 #define __DEFINED_max_align_t 200 #endif 201 202 #if defined(__x86_64__) && defined(__FLT_EVAL_METHOD__) && __FLT_EVAL_METHOD__ == 2 203 #if defined(__NEED_float_t) && !defined(__DEFINED_float_t) 204 typedef long double float_t; 205 #define __DEFINED_float_t 206 #endif 207 208 #if defined(__NEED_double_t) && !defined(__DEFINED_double_t) 209 typedef long double double_t; 210 #define __DEFINED_double_t 211 #endif 212 213 #else 214 #if defined(__NEED_float_t) && !defined(__DEFINED_float_t) 215 typedef float float_t; 216 #define __DEFINED_float_t 217 #endif 218 219 #if defined(__NEED_double_t) && !defined(__DEFINED_double_t) 220 typedef double double_t; 221 #define __DEFINED_double_t 222 #endif 223 224 #endif 225 226 #if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) 227 typedef long suseconds_t; 228 #define __DEFINED_suseconds_t 229 #endif 230 231 #if defined(__NEED_useconds_t) && !defined(__DEFINED_useconds_t) 232 typedef unsigned useconds_t; 233 #define __DEFINED_useconds_t 234 #endif 235 236 #if defined(__NEED_clockid_t) && !defined(__DEFINED_clockid_t) 237 typedef int clockid_t; 238 #define __DEFINED_clockid_t 239 #endif 240 241 #if defined(__NEED_clock_t) && !defined(__DEFINED_clock_t) 242 typedef long clock_t; 243 #define __DEFINED_clock_t 244 #endif 245 246 #if defined(__NEED_pid_t) && !defined(__DEFINED_pid_t) 247 typedef int pid_t; 248 #define __DEFINED_pid_t 249 #endif 250 251 #if defined(__NEED_id_t) && !defined(__DEFINED_id_t) 252 typedef unsigned id_t; 253 #define __DEFINED_id_t 254 #endif 255 256 #if defined(__NEED_uid_t) && !defined(__DEFINED_uid_t) 257 typedef unsigned uid_t; 258 #define __DEFINED_uid_t 259 #endif 260 261 #if defined(__NEED_gid_t) && !defined(__DEFINED_gid_t) 262 typedef unsigned gid_t; 263 #define __DEFINED_gid_t 264 #endif 265 266 #if defined(__NEED_register_t) && !defined(__DEFINED_register_t) 267 typedef long register_t; 268 #define __DEFINED_register_t 269 #endif 270 271 #if defined(__NEED_nlink_t) && !defined(__DEFINED_nlink_t) 272 typedef unsigned long nlink_t; 273 #define __DEFINED_nlink_t 274 #endif 275 276 #if defined(__NEED_off_t) && !defined(__DEFINED_off_t) 277 typedef long long off_t; 278 #define __DEFINED_off_t 279 #endif 280 281 #if defined(__NEED_ino_t) && !defined(__DEFINED_ino_t) 282 typedef unsigned long long ino_t; 283 #define __DEFINED_ino_t 284 #endif 285 286 #if defined(__NEED_dev_t) && !defined(__DEFINED_dev_t) 287 typedef unsigned long long dev_t; 288 #define __DEFINED_dev_t 289 #endif 290 291 #if defined(__NEED_blksize_t) && !defined(__DEFINED_blksize_t) 292 typedef long blksize_t; 293 #define __DEFINED_blksize_t 294 #endif 295 296 #if defined(__NEED_blkcnt_t) && !defined(__DEFINED_blkcnt_t) 297 typedef long long blkcnt_t; 298 #define __DEFINED_blkcnt_t 299 #endif 300 301 #if defined(__NEED_fsblkcnt_t) && !defined(__DEFINED_fsblkcnt_t) 302 typedef unsigned long long fsblkcnt_t; 303 #define __DEFINED_fsblkcnt_t 304 #endif 305 306 #if defined(__NEED_fsfilcnt_t) && !defined(__DEFINED_fsfilcnt_t) 307 typedef unsigned long long fsfilcnt_t; 308 #define __DEFINED_fsfilcnt_t 309 #endif 310 311 #if defined(__NEED_struct_iovec) && !defined(__DEFINED_struct_iovec) 312 struct iovec { 313 void* iov_base; 314 size_t iov_len; 315 }; 316 #define __DEFINED_struct_iovec 317 #endif 318 319 #if defined(__NEED_struct_timeval) && !defined(__DEFINED_struct_timeval) 320 struct timeval { 321 time_t tv_sec; 322 suseconds_t tv_usec; 323 }; 324 #define __DEFINED_struct_timeval 325 #endif 326 327 #if defined(__NEED_struct_timespec) && !defined(__DEFINED_struct_timespec) 328 struct timespec { 329 time_t tv_sec; 330 long tv_nsec; 331 }; 332 #define __DEFINED_struct_timespec 333 #endif 334 335 #if defined(__NEED_key_t) && !defined(__DEFINED_key_t) 336 typedef int key_t; 337 #define __DEFINED_key_t 338 #endif 339 340 #if defined(__NEED_timer_t) && !defined(__DEFINED_timer_t) 341 typedef void* timer_t; 342 #define __DEFINED_timer_t 343 #endif 344 345 #if defined(__NEED_regoff_t) && !defined(__DEFINED_regoff_t) 346 typedef long regoff_t; 347 #define __DEFINED_regoff_t 348 #endif 349 350 #if defined(__NEED_socklen_t) && !defined(__DEFINED_socklen_t) 351 typedef unsigned socklen_t; 352 #define __DEFINED_socklen_t 353 #endif 354 355 #if defined(__NEED_sa_family_t) && !defined(__DEFINED_sa_family_t) 356 typedef unsigned short sa_family_t; 357 #define __DEFINED_sa_family_t 358 #endif 359 360 #if defined(__NEED_FILE) && !defined(__DEFINED_FILE) 361 typedef struct _IO_FILE FILE; 362 #define __DEFINED_FILE 363 #endif 364 365 #if defined(__NEED_locale_t) && !defined(__DEFINED_locale_t) 366 typedef struct __locale_struct* locale_t; 367 #define __DEFINED_locale_t 368 #endif 369 370 #if defined(__NEED_mode_t) && !defined(__DEFINED_mode_t) 371 typedef unsigned mode_t; 372 #define __DEFINED_mode_t 373 #endif 374 375 #if defined(__NEED_sigset_t) && !defined(__DEFINED_sigset_t) 376 typedef struct __sigset_t { unsigned long __bits[128 / sizeof(long)]; } sigset_t; 377 #define __DEFINED_sigset_t 378 #endif 379 380 #if defined(__NEED_pthread_once_t) && !defined(__DEFINED_pthread_once_t) 381 typedef __C11_ATOMIC(int) pthread_once_t; 382 #define __DEFINED_pthread_once_t 383 #endif 384 385 #if defined(__NEED_once_flag) && !defined(__DEFINED_once_flag) 386 typedef __C11_ATOMIC(int) once_flag; 387 #define __DEFINED_once_flag 388 #endif 389 390 #if defined(__NEED_pthread_key_t) && !defined(__DEFINED_pthread_key_t) 391 typedef unsigned pthread_key_t; 392 #define __DEFINED_pthread_key_t 393 #endif 394 395 #if defined(__NEED_pthread_spinlock_t) && !defined(__DEFINED_pthread_spinlock_t) 396 typedef __C11_ATOMIC(int) pthread_spinlock_t; 397 #define __DEFINED_pthread_spinlock_t 398 #endif 399 400 #if defined(__NEED_pthread_mutexattr_t) && !defined(__DEFINED_pthread_mutexattr_t) 401 typedef struct { unsigned __attr; } pthread_mutexattr_t; 402 #define __DEFINED_pthread_mutexattr_t 403 #endif 404 405 #if defined(__NEED_pthread_condattr_t) && !defined(__DEFINED_pthread_condattr_t) 406 typedef struct { unsigned __attr; } pthread_condattr_t; 407 #define __DEFINED_pthread_condattr_t 408 #endif 409 410 #if defined(__NEED_pthread_barrierattr_t) && !defined(__DEFINED_pthread_barrierattr_t) 411 typedef struct { unsigned __attr; } pthread_barrierattr_t; 412 #define __DEFINED_pthread_barrierattr_t 413 #endif 414 415 #if defined(__NEED_pthread_rwlockattr_t) && !defined(__DEFINED_pthread_rwlockattr_t) 416 typedef struct { unsigned __attr[2]; } pthread_rwlockattr_t; 417 #define __DEFINED_pthread_rwlockattr_t 418 #endif 419 420 #ifdef __cplusplus 421 #if defined(__NEED_pthread_t) && !defined(__DEFINED_pthread_t) 422 typedef unsigned long pthread_t; 423 #define __DEFINED_pthread_t 424 #endif 425 426 #else 427 #if defined(__NEED_pthread_t) && !defined(__DEFINED_pthread_t) 428 typedef struct __pthread* pthread_t; 429 #define __DEFINED_pthread_t 430 #endif 431 432 #endif 433 434 #if defined(__NEED_mbstate_t) && !defined(__DEFINED_mbstate_t) 435 typedef struct __mbstate_t { unsigned __opaque1, __opaque2; } mbstate_t; 436 #define __DEFINED_mbstate_t 437 #endif 438 439 #if defined(__NEED_pthread_attr_t) && !defined(__DEFINED_pthread_attr_t) 440 typedef struct { 441 const char* __name; 442 int __c11; 443 size_t _a_stacksize; 444 size_t _a_guardsize; 445 void* _a_stackaddr; 446 int _a_detach; 447 int _a_sched; 448 int _a_policy; 449 int _a_prio; 450 } pthread_attr_t; 451 #define __DEFINED_pthread_attr_t 452 #endif 453 454 #if defined(__NEED_pthread_mutex_t) && !defined(__DEFINED_pthread_mutex_t) 455 typedef struct { 456 int _m_type; 457 __C11_ATOMIC(int) _m_lock; 458 __C11_ATOMIC(int) _m_waiters; 459 int _m_count; 460 } pthread_mutex_t; 461 #define __DEFINED_pthread_mutex_t 462 #endif 463 464 #if defined(__NEED_mtx_t) && !defined(__DEFINED_mtx_t) 465 typedef struct 466 #if defined(__clang__) 467 __attribute__((__capability__("mutex"))) 468 #endif 469 { 470 int __i[1]; 471 } mtx_t; 472 #define __DEFINED_mtx_t 473 #endif 474 475 #if defined(__NEED_pthread_cond_t) && !defined(__DEFINED_pthread_cond_t) 476 typedef struct { 477 void* _c_head; 478 int _c_clock; 479 void* _c_tail; 480 __C11_ATOMIC(int) _c_lock; 481 } pthread_cond_t; 482 #define __DEFINED_pthread_cond_t 483 #endif 484 485 #if defined(__NEED_cnd_t) && !defined(__DEFINED_cnd_t) 486 typedef struct { 487 void* _c_head; 488 int _c_clock; 489 void* _c_tail; 490 __C11_ATOMIC(int) _c_lock; 491 } cnd_t; 492 #define __DEFINED_cnd_t 493 #endif 494 495 #if defined(__NEED_pthread_rwlock_t) && !defined(__DEFINED_pthread_rwlock_t) 496 typedef struct { 497 __C11_ATOMIC(int) _rw_lock; 498 __C11_ATOMIC(int) _rw_waiters; 499 } pthread_rwlock_t; 500 #define __DEFINED_pthread_rwlock_t 501 #endif 502 503 #if defined(__NEED_pthread_barrier_t) && !defined(__DEFINED_pthread_barrier_t) 504 typedef struct { 505 __C11_ATOMIC(int) _b_lock; 506 __C11_ATOMIC(int) _b_waiters; 507 unsigned int _b_limit; 508 __C11_ATOMIC(int) _b_count; 509 __C11_ATOMIC(int) _b_waiters2; 510 void* _b_inst; 511 } pthread_barrier_t; 512 #define __DEFINED_pthread_barrier_t 513 #endif 514 515 #if defined(__NEED_sem_t) && !defined(__DEFINED_sem_t) 516 typedef struct { 517 __C11_ATOMIC(int) _s_value; 518 __C11_ATOMIC(int) _s_waiters; 519 } sem_t; 520 #define __DEFINED_sem_t 521 #endif 522