root/src/libsir/include/sir/platform.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * platform.h
   3  *
   4  * Version: 2.2.5
   5  *
   6  * -----------------------------------------------------------------------------
   7  *
   8  * SPDX-License-Identifier: MIT
   9  *
  10  * Copyright (c) 2018-2024 Ryan M. Lederman <lederman@gmail.com>
  11  * Copyright (c) 2018-2024 Jeffrey H. Johnson <trnsz@pobox.com>
  12  *
  13  * Permission is hereby granted, free of charge, to any person obtaining a copy of
  14  * this software and associated documentation files (the "Software"), to deal in
  15  * the Software without restriction, including without limitation the rights to
  16  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  17  * the Software, and to permit persons to whom the Software is furnished to do so,
  18  * subject to the following conditions:
  19  *
  20  * The above copyright notice and this permission notice shall be included in all
  21  * copies or substantial portions of the Software.
  22  *
  23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  25  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  26  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  27  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  28  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29  *
  30  * -----------------------------------------------------------------------------
  31  */
  32 
  33 #ifndef _SIR_PLATFORM_H_INCLUDED
  34 # define _SIR_PLATFORM_H_INCLUDED
  35 
  36 # if defined(_MSC_VER) && !defined(__clang__)
  37 #  include <stddef.h>
  38 #  undef _USE_ATTRIBUTES_FOR_SAL
  39 #  define _USE_ATTRIBUTES_FOR_SAL 1
  40 #  include <sal.h>
  41 #  define PRINTF_FORMAT _Printf_format_string_
  42 #  define PRINTF_FORMAT_ATTR(fmt_p, va_p)
  43 # else
  44 #  define PRINTF_FORMAT
  45 #  if (defined(__MINGW32__) || defined(__MINGW64__)) && \
  46      !defined(__clang_version__)
  47 #   if !defined(__USE_MINGW_ANSI_STDIO)
  48 #    define __USE_MINGW_ANSI_STDIO 1
  49 #   endif
  50 #   define PRINTF_FORMAT_ATTR(fmt_p, va_p) \
  51     __attribute__((format (gnu_printf, fmt_p, va_p)))
  52 #  else
  53 #   if !defined(__SUNPRO_C) && !defined(__SUNPRO_CC) && \
  54       !defined(_CH_) && !defined(__CH__)
  55 #    define PRINTF_FORMAT_ATTR(fmt_p, va_p) \
  56      __attribute__((format (printf, fmt_p, va_p)))
  57 #   else
  58 #    define PRINTF_FORMAT_ATTR(fmt_p, va_p)
  59 #   endif
  60 #  endif
  61 # endif
  62 
  63 # undef HAS_ATTRIBUTE
  64 # if defined __has_attribute && (defined(__clang__) || defined(__GNUC__))
  65 #  define HAS_ATTRIBUTE(atr) __has_attribute(atr)
  66 # else
  67 #  define HAS_ATTRIBUTE(atr) 0
  68 # endif
  69 
  70 # undef HAS_INCLUDE
  71 # if defined __has_include
  72 #  define HAS_INCLUDE(inc) __has_include(inc)
  73 # else
  74 #  define HAS_INCLUDE(inc) 0
  75 # endif
  76 
  77 # undef HAS_FEATURE
  78 # if defined __has_feature
  79 #  define HAS_FEATURE(fea) __has_feature(fea)
  80 # else
  81 #  define HAS_FEATURE(fea) 0
  82 # endif
  83 
  84 # undef SANITIZE_SUPPRESS
  85 # if HAS_ATTRIBUTE(no_sanitize)
  86 #  define SANITIZE_SUPPRESS(str) __attribute__((no_sanitize(str)))
  87 # endif
  88 # if !defined(SANITIZE_SUPPRESS)
  89 #  define SANITIZE_SUPPRESS(str)
  90 # endif
  91 
  92 # if HAS_FEATURE(safe_stack) && !defined(SIR_NO_PLUGINS)
  93 #  error "linking DSOs with SafeStack is unsupported; disable SafeStack or enable SIR_NO_PLUGINS"
  94 # endif
  95 
  96 # if defined(__OPENOSC_H__)
  97 #  define SIR_IMPL_STRNLEN
  98 # endif
  99 
 100 # if !defined(_WIN32)
 101 #  if defined(__STDC_NO_ATOMICS__)
 102 #   undef __HAVE_ATOMIC_H__
 103 #  else
 104 #   define __HAVE_ATOMIC_H__
 105 #  endif
 106 #  if defined(__GNUC__) && __GNUC__ <= 4
 107 #   if defined(__GNUC_MINOR__) && __GNUC_MINOR__ <= 8
 108 #    if !defined(__clang_version__)
 109 #     undef __HAVE_ATOMIC_H__
 110 #    endif
 111 #   endif
 112 #  endif
 113 #  if defined(__DragonFly__)
 114 #   if defined(__clang__) && defined(__clang_version__)
 115 #    undef __HAVE_ATOMIC_H__
 116 #   endif
 117 #  endif
 118 #  if defined(__circle_lang__)
 119 #   undef __HAVE_ATOMIC_H__
 120 #  endif
 121 #  if defined(SUNLINT)
 122 #   undef __HAVE_ATOMIC_H__
 123 #  endif
 124 #  if (defined(__INTEL_COMPILER) && !defined(__llvm__)) || \
 125      defined(__NVCOMPILER) || defined(__COVERITY__)
 126 #   if !defined(_BITS_FLOATN_H)
 127 #    define _BITS_FLOATN_H
 128 #   endif
 129 #  endif
 130 #  if defined(__IMPORTC__)
 131 #   include "sir/platform_importc.h"
 132 #  endif
 133 #  if !defined(__open_xl__) && defined(__ibmxl__) && defined(__ibmxl_release__)
 134 #   if __ibmxl__ <= 16
 135 #    if __ibmxl_release__ <= 1
 136 #     undef __HAVE_ATOMIC_H__
 137 #    endif
 138 #   endif
 139 #  endif
 140 #  if !defined(__open_xl__) && defined(__xlC_ver__) && defined(__IBMC__)
 141 #   if __IBMC__ <= 1610
 142 #    undef __HAVE_ATOMIC_H__
 143 #   endif
 144 #   define __XLC16__ 1
 145 #  endif
 146 #  if !defined(__STDC_WANT_LIB_EXT1__)
 147 #   define __STDC_WANT_LIB_EXT1__ 1
 148 #  endif
 149 #  if !defined(__STDC_WANT_LIB_EXT2__)
 150 #   define __STDC_WANT_LIB_EXT2__ 1
 151 #  endif
 152 #  if defined(__APPLE__) && defined(__MACH__)
 153 #   define __MACOS__
 154 #   undef _DARWIN_C_SOURCE
 155 #   define _DARWIN_C_SOURCE
 156 #  elif defined(__serenity__)
 157 #   define SIR_PTHREAD_GETNAME_NP
 158 #  elif defined(__OpenBSD__)
 159 #   define __BSD__
 160 #   define __FreeBSD_PTHREAD_NP_11_3__
 161 #  elif defined(__NetBSD__)
 162 #   define __BSD__
 163 #   if !defined(_NETBSD_SOURCE)
 164 #    define _NETBSD_SOURCE 1
 165 #   endif
 166 #   define SIR_PTHREAD_GETNAME_NP
 167 #   define __USE_HEX_TIDS__
 168 #  elif defined(__FreeBSD__) || defined(__DragonFly__)
 169 #   define __BSD__
 170 #   define _BSD_SOURCE
 171 #   if !defined(_DEFAULT_SOURCE)
 172 #    define _DEFAULT_SOURCE
 173 #   endif
 174 #   include <sys/param.h>
 175 #   if __FreeBSD_version >= 1202500
 176 #    define __FreeBSD_PTHREAD_NP_12_2__
 177 #   elif __FreeBSD_version >= 1103500
 178 #    define __FreeBSD_PTHREAD_NP_11_3__
 179 #   elif __DragonFly_version >= 400907
 180 #    define __DragonFly_getthreadid__
 181 #   endif
 182 #   if defined(__DragonFly__)
 183 #    define SIR_PTHREAD_GETNAME_NP
 184 #   endif
 185 #  else
 186 #   if defined(__EMSCRIPTEN__)
 187 #    define __USE_GNU
 188 #    define _GNU_SOURCE 1
 189 #    undef SIR_NO_THREAD_NAMES
 190 #    define SIR_NO_THREAD_NAMES
 191 #    include <emscripten.h>
 192 #   endif
 193 #   if defined(__HAIKU__)
 194 #    if !defined(__USE_GNU)
 195 #     define __USE_GNU
 196 #    endif
 197 #    if !defined(_GNU_SOURCE)
 198 #     define _GNU_SOURCE 1
 199 #    endif
 200 #    if defined(__clang__) && !defined(_GNU_PTHREAD_H_)
 201 #     include <pthread.h>
 202 extern /* Workaround a Clang on Haiku bug. */
 203 int pthread_getname_np(pthread_t thread, char* buffer, size_t length);
 204 #    endif
 205 #    define SIR_PTHREAD_GETNAME_NP
 206 #   endif
 207 #   if defined(__GNU__) && !defined(__linux__)
 208 #    undef SIR_NO_THREAD_NAMES
 209 #    define SIR_NO_THREAD_NAMES
 210 #    if !defined(__HURD__)
 211 #     define __HURD__ 1
 212 #    endif
 213 #   endif
 214 #   if defined(__linux__)
 215 #    if !defined(_GNU_SOURCE)
 216 #     define _GNU_SOURCE 1
 217 #    endif
 218 #    include <features.h>
 219 #    if defined(__GLIBC__)
 220 #     undef GLIBC_VERSION
 221 #     define GLIBC_VERSION (((0 + __GLIBC__) * 10000) + ((0 + __GLIBC_MINOR__) * 100))
 222 #    endif
 223 #    if !defined(GLIBC_VERSION)
 224 #     define GLIBC_VERSION 0
 225 #    endif
 226 #    if defined(__GLIBC__) && GLIBC_VERSION >= 21200
 227 #     define SIR_PTHREAD_GETNAME_NP
 228 #    endif
 229 #    if defined(__GLIBC__) && GLIBC_VERSION > 0 && GLIBC_VERSION < 21200
 230 #     undef SIR_NO_THREAD_NAMES
 231 #     define SIR_NO_THREAD_NAMES
 232 #    endif
 233 #    if defined(__GLIBC__) && GLIBC_VERSION > 0 && \
 234        !defined(__SUNPRO_C) && !defined(__SUNPRO_CC)
 235 #     include <sys/sysinfo.h>
 236 #    endif
 237 #   endif
 238 #   if defined(__CYGWIN__)
 239 #    if !defined(_GNU_SOURCE)
 240 #     define _GNU_SOURCE 1
 241 #    endif
 242 #    define SIR_PTHREAD_GETNAME_NP
 243 #    include <sys/features.h>
 244 #   endif
 245 #   if defined(__ANDROID__) && defined(__ANDROID_API__)
 246 #    if __ANDROID_API__ < 26
 247 #     undef SIR_PTHREAD_GETNAME_NP
 248 #     undef SIR_NO_THREAD_NAMES
 249 #     define SIR_NO_THREAD_NAMES
 250 #    endif
 251 #   endif
 252 #   if defined(__illumos__) || ((defined(__sun) || defined(__sun__)) && \
 253            (defined(__SVR4) || defined(__svr4__)))
 254 #    define __SOLARIS__
 255 #    define SIR_PTHREAD_GETNAME_NP
 256 #    if !defined(_ATFILE_SOURCE)
 257 #     define _ATFILE_SOURCE 1
 258 #    endif
 259 #    if !defined(__EXTENSIONS__)
 260 #     define __EXTENSIONS__
 261 #    endif
 262 #   endif
 263 #   if !defined(_POSIX_C_SOURCE)
 264 #    define _POSIX_C_SOURCE 200809L
 265 #   endif
 266 #   if !defined(_DEFAULT_SOURCE)
 267 #    define _DEFAULT_SOURCE
 268 #   endif
 269 #   if !defined(_XOPEN_SOURCE)
 270 #    define _XOPEN_SOURCE 700
 271 #   endif
 272 #  endif
 273 # else /* _WIN32 */
 274 #  define __WIN__
 275 #  define __WANT_STDC_SECURE_LIB__ 1
 276 #  define WIN32_LEAN_AND_MEAN
 277 #  undef WINVER
 278 #  define WINVER       0x0A00 /** Windows 10 SDK */
 279 #  undef _WIN32_WINNT
 280 #  define _WIN32_WINNT 0x0A00
 281 #  define _CRT_RAND_S
 282 #  define NOMINMAX
 283 #  if defined(__ORANGEC__)
 284 #   include "sir/platform_orangec.h"
 285 #  endif
 286 #  if defined(__MINGW32__) || defined(__MINGW64__)
 287 #   define SIR_PTHREAD_GETNAME_NP
 288 #  endif
 289 #  include <windows.h>
 290 #  include <io.h>
 291 #  include <synchapi.h>
 292 #  include <processthreadsapi.h>
 293 #  include <process.h>
 294 #  include <winsock2.h>
 295 #  include <conio.h>
 296 #  include <shlwapi.h>
 297 #  include <evntprov.h>
 298 #  undef __HAVE_ATOMIC_H__
 299 #  if defined(_MSC_VER) && _MSC_VER >= 1933 && \
 300       !defined(__cplusplus) && !defined(__IMPORTC__)
 301 #   include <stdatomic.h>
 302 #   define __HAVE_ATOMIC_H__
 303 #  endif
 304 #  if defined(__MINGW32__) || defined(__MINGW64__)
 305 #   undef __USE_MINGW_ANSI_STDIO
 306 #   define __USE_MINGW_ANSI_STDIO 1
 307 #   include <pthread.h>
 308 typedef /* Workaround a MinGW bug */
 309 void (__cdecl* _invalid_parameter_handler)(
 310  wchar_t const*, wchar_t const*, wchar_t const*,
 311  unsigned int, uintptr_t);
 312 _invalid_parameter_handler
 313 _set_thread_local_invalid_parameter_handler(
 314  _invalid_parameter_handler pNew);
 315 #  endif
 316 #  include "sir/platform_embarcadero.h"
 317 # endif
 318 
 319 # if !defined(__MACOS__) && !defined(__BSD__) && !defined(__SOLARIS__) && \
 320      !defined(__HAIKU__) && !(defined(__GLIBC__) && GLIBC_VERSION >= 23800)
 321 #  define SIR_IMPL_STRLCPY 1
 322 #  define SIR_IMPL_STRLCAT 1
 323 # endif
 324 
 325 # if defined(__WIN__)
 326 #  define SIR_IMPL_STRNDUP 1
 327 # endif
 328 
 329 # if defined(_AIX)
 330 #  define SIR_IMPL_STRCASESTR 1
 331 # endif
 332 
 333 # if defined(__MINGW64__)
 334 #  define PID_CAST (int)
 335 # else
 336 #  define PID_CAST
 337 # endif
 338 
 339 # if defined(_AIX) || defined(__CYGWIN__)
 340 #  define CLOCK_CAST (int)
 341 # else
 342 #  define CLOCK_CAST
 343 # endif
 344 
 345 # if defined(_AIX)
 346 #  if !defined(_ALL_SOURCE)
 347 #   define _ALL_SOURCE
 348 #  endif
 349 #  if defined(_GNU_SOURCE)
 350 #   undef _GNU_SOURCE
 351 #  endif
 352 #  if !defined(_THREAD_SAFE)
 353 #   define _THREAD_SAFE
 354 #  endif
 355 # endif
 356 
 357 # if defined(SIR_ASSERT_ENABLED)
 358 #  include <assert.h>
 359 #  define SIR_ASSERT(...) assert(__VA_ARGS__)
 360 # else
 361 #  if defined(SIR_SELFLOG)
 362 #   define SIR_ASSERT(...) \
 363      do { \
 364           if (!(__VA_ARGS__)) { \
 365                _sir_selflog(SIR_BRED("!!! would be asserting: " #__VA_ARGS__ "")); \
 366           } \
 367      } while (false)
 368 #  else
 369 #   define SIR_ASSERT(...)
 370 #  endif
 371 # endif
 372 
 373 # if defined(__cplusplus) && !defined(restrict)
 374 #  define restrict //-V1059
 375 # endif
 376 
 377 # include <ctype.h>
 378 # include <errno.h>
 379 # include <stdarg.h>
 380 # include <stdbool.h>
 381 # include <stdint.h>
 382 # include <inttypes.h>
 383 # include <stdio.h>
 384 
 385 # if defined(__cplusplus) && defined(__NVCOMPILER) && defined(__FLOAT128__)
 386 #  define NVIDIA_FLOAT128 __FLOAT128__
 387 #  undef __FLOAT128__
 388 # endif
 389 
 390 # include <stdlib.h>
 391 
 392 # if defined(NVIDIA_FLOAT128)
 393 #  define __FLOAT128__ NVIDIA_FLOAT128
 394 #  undef NVIDIA_FLOAT128
 395 # endif
 396 
 397 # include <string.h>
 398 
 399 # if defined(DUMA)
 400 #  include <duma.h>
 401 # endif
 402 
 403 # include <sys/stat.h>
 404 # include <sys/types.h>
 405 # include <limits.h>
 406 # include <time.h>
 407 
 408 # if !defined(SIR_NO_SYSTEM_LOGGERS)
 409 #  if defined(__MACOS__) && !defined(__IMPORTC__) && \
 410       ((defined(__clang__) || defined(__clang_version__)) && \
 411       !(defined(__INTEL_COMPILER) && !defined(__llvm__)) && \
 412       defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__))
 413 #   undef SIR_OS_LOG_ENABLED
 414 #   define SIR_OS_LOG_ENABLED
 415 #  elif defined(__WIN__)
 416 #   undef SIR_EVENTLOG_ENABLED
 417 #   if defined(__EMBARCADEROC__) || defined(__ORANGEC__)
 418 #    define SIR_NO_SYSTEM_LOGGERS
 419 #   else
 420 #    define SIR_EVENTLOG_ENABLED
 421 #   endif
 422 #  else
 423 #   undef SIR_OS_LOG_ENABLED
 424 #   define SIR_SYSLOG_ENABLED
 425 #  endif
 426 # else
 427 #  undef SIR_OS_LOG_ENABLED
 428 #  undef SIR_SYSLOG_ENABLED
 429 # endif
 430 
 431 # define SIR_MAXHOST 256
 432 
 433 # if !defined(__WIN__)
 434 #  if !defined(SIR_NO_PLUGINS)
 435 #   include <dlfcn.h>
 436 #  endif
 437 #  if !defined(_CH_) && !defined(__CH__)
 438 #   include <pthread.h>
 439 #  else
 440 #   include <sched.h>
 441 #   include <ch/pthread.h>
 442 #   undef __HAVE_ATOMIC_H__
 443 #  endif
 444 #  if defined(__illumos__)
 445 #   include <sys/fcntl.h>
 446 #  endif
 447 #  if defined(__linux__) && defined(__USE_GNU) && \
 448              (defined(__SUNPRO_C) || defined(__SUNPRO_CC))
 449 #   undef __USE_GNU
 450 #   include <fcntl.h>
 451 #   define __USE_GNU
 452 #  else
 453 #   include <fcntl.h>
 454 #  endif
 455 #  include <unistd.h>
 456 #  if defined(__MACOS__)
 457 #   include <sys/sysctl.h>
 458 #  endif
 459 #  if !defined(__CYGWIN__) && !defined(__HAIKU__) && \
 460       !defined(__serenity__) && !defined(_AIX) && \
 461       !defined(_CH_) && !defined(__CH__)
 462 #   include <sys/syscall.h>
 463 #  endif
 464 #  include <sys/time.h>
 465 #  include <strings.h>
 466 #  include <termios.h>
 467 #  include <limits.h>
 468 #  include <libgen.h>
 469 #  if defined(__HAVE_ATOMIC_H__) && !defined(__cplusplus)
 470 #   include <stdatomic.h>
 471 #  endif
 472 #  if defined(SIR_SYSLOG_ENABLED)
 473 #   if !defined(__cplusplus)
 474 #    include <syslog.h>
 475 #   endif
 476 #  endif
 477 #  if defined(__CYGWIN__)
 478 #   undef SIR_NO_THREAD_NAMES
 479 #   define SIR_NO_THREAD_NAMES
 480 #  endif
 481 #  if defined(_AIX)
 482 #   include <procinfo.h>
 483 #   include <sys/procfs.h>
 484 #   include <sys/systemcfg.h>
 485 #   undef SIR_NO_THREAD_NAMES
 486 #   define SIR_NO_THREAD_NAMES
 487 #  endif
 488 #  if defined(__BSD__)
 489 #   if !defined(__NetBSD__)
 490 #    include <pthread_np.h>
 491 #   endif
 492 #   include <sys/sysctl.h>
 493 #  elif defined(__linux__)
 494 #   if defined(__GLIBC__)
 495 #    include <linux/limits.h>
 496 #   endif
 497 #  elif defined(__HAIKU__)
 498 #   include <OS.h>
 499 #   include <FindDirectory.h>
 500 #  elif defined(__MACOS__)
 501 #   include <mach-o/dyld.h>
 502 #   if defined(SIR_OS_LOG_ENABLED)
 503 #    include <os/log.h>
 504 #    include <os/trace.h>
 505 #    include <os/activity.h>
 506 #   endif
 507 #  endif
 508 
 509 #  if defined(PATH_MAX)
 510 #   define SIR_MAXPATH PATH_MAX
 511 #  elif defined(MAXPATHLEN)
 512 #   define SIR_MAXPATH MAXPATHLEN
 513 #  else
 514 #   define SIR_MAXPATH 1024
 515 #  endif
 516 
 517 #  if !defined(SIR_MAXPID) && defined(HAIKU) && defined(B_OS_NAME_LENGTH)
 518 #   define SIR_MAXPID B_OS_NAME_LENGTH
 519 #  endif
 520 #  if !defined(SIR_MAXPID) && defined(PTHREAD_MAX_NAMELEN_NP)
 521 #   define SIR_MAXPID PTHREAD_MAX_NAMELEN_NP
 522 #  endif
 523 #  if !defined(SIR_MAXPID) && defined(_NTO_THREAD_NAME_MAX)
 524 #   define SIR_MAXPID _NTO_THREAD_NAME_MAX
 525 #  endif
 526 #  if !defined(SIR_MAXPID) && defined(__APPLE__)
 527 #   define SIR_MAXPID 64
 528 #  endif
 529 #  if !defined(SIR_MAXPID) && defined(__OpenBSD__)
 530 #   define SIR_MAXPID 32
 531 #  endif
 532 #  if !defined(SIR_MAXPID) && defined(__SOLARIS__)
 533 #   define SIR_MAXPID 31
 534 #  endif
 535 #  if !defined(SIR_MAXPID) && defined(__linux__)
 536 #   define SIR_MAXPID 16
 537 #  endif
 538 #  if !defined(SIR_MAXPID)
 539 #   define SIR_MAXPID 15
 540 #  endif
 541 
 542 #  if (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0) || \
 543        defined(__MACOS__) || defined(__OpenBSD__)
 544 #   define SIR_MSEC_TIMER
 545 #   define SIR_MSEC_POSIX
 546 #  else
 547 #   undef SIR_MSEC_TIMER
 548 #  endif
 549 
 550 /** The clock used to obtain timestamps. */
 551 #  if defined(CLOCK_REALTIME_FAST)
 552 #   define SIR_WALLCLOCK CLOCK_REALTIME_FAST
 553 #  elif defined(CLOCK_REALTIME_COARSE)
 554 #   define SIR_WALLCLOCK CLOCK_REALTIME_COARSE
 555 #  else
 556 #   define SIR_WALLCLOCK CLOCK_REALTIME
 557 #  endif
 558 
 559 /** The clock used to measure intervals. */
 560 #  if defined(CLOCK_UPTIME)
 561 #   define SIR_INTERVALCLOCK CLOCK_UPTIME
 562 #  elif defined(CLOCK_BOOTTIME) && !defined(__EMSCRIPTEN__)
 563 #   define SIR_INTERVALCLOCK CLOCK_BOOTTIME
 564 #  elif defined(CLOCK_HIGHRES)
 565 #   define SIR_INTERVALCLOCK CLOCK_HIGHRES
 566 #  elif defined(CLOCK_MONOTONIC)
 567 #   define SIR_INTERVALCLOCK CLOCK_MONOTONIC
 568 #  else
 569 #   define SIR_INTERVALCLOCK CLOCK_REALTIME
 570 #  endif
 571 
 572 /** The plugin handle type. */
 573 typedef void* sir_pluginhandle;
 574 
 575 /** The plugin export address type. */
 576 typedef void (*sir_pluginexport)(void);
 577 
 578 /** The mutex type. */
 579 typedef pthread_mutex_t sir_mutex;
 580 
 581 /** The thread type. */
 582 typedef pthread_t sir_thread;
 583 
 584 /** The condition variable type. */
 585 typedef pthread_cond_t sir_condition;
 586 
 587 /** The mutex/condition variable wait time type. */
 588 typedef struct timespec sir_wait;
 589 
 590 /** The one-time type. */
 591 typedef pthread_once_t sir_once;
 592 
 593 /** The one-time execution function type. */
 594 typedef void (*sir_once_fn)(void);
 595 
 596 /** The one-time initializer. */
 597 #  define SIR_ONCE_INIT PTHREAD_ONCE_INIT
 598 
 599 /** The mutex initializer. */
 600 #  define SIR_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
 601 
 602 # else /* __WIN__ */
 603 
 604 #  define SIR_MAXPID 64
 605 
 606 #  define SIR_MAXPATH MAX_PATH
 607 
 608 #  define SIR_MSEC_TIMER
 609 #  define SIR_MSEC_WIN32
 610 #  define SIR_WALLCLOCK 0
 611 #  define SIR_INTERVALCLOCK 1
 612 
 613 /** The plugin handle type. */
 614 typedef HMODULE sir_pluginhandle;
 615 
 616 /** The plugin export address type. */
 617 typedef FARPROC sir_pluginexport;
 618 
 619 /** The mutex type. */
 620 typedef CRITICAL_SECTION sir_mutex;
 621 
 622 /** The thread type. */
 623 typedef HANDLE sir_thread;
 624 
 625 /** The condition variable type. */
 626 typedef CONDITION_VARIABLE sir_condition;
 627 
 628 /** The mutex/condition variable wait time type. */
 629 typedef DWORD sir_wait;
 630 
 631 /** The one-time type. */
 632 typedef INIT_ONCE sir_once;
 633 
 634 /** Process/thread ID. */
 635 #  if !defined(__MINGW64__) && !defined(__MINGW32__) && !defined(__ORANGEC__)
 636 typedef int pid_t;
 637 #  endif
 638 
 639 /** The one-time execution function type. */
 640 typedef BOOL(CALLBACK* sir_once_fn)(PINIT_ONCE, PVOID, PVOID*);
 641 
 642 /** The one-time initializer. */
 643 #  define SIR_ONCE_INIT INIT_ONCE_STATIC_INIT
 644 
 645 /** The mutex initializer. */
 646 #  define SIR_MUTEX_INIT {0}
 647 
 648 # endif /* !__WIN__ */
 649 
 650 # if !defined(_sir_thread_local)
 651 #  if (__STDC_VERSION__ >= 201112 && !defined(__STDC_NO_THREADS__)) || \
 652      (defined(__SUNPRO_C) || defined(__SUNPRO_CC))
 653 #   if defined(_AIX) && defined(__GNUC__)
 654 #    define _sir_thread_local __thread
 655 #   else
 656 #    define _sir_thread_local _Thread_local
 657 #   endif
 658 #  elif defined(__WIN__)
 659 #   define _sir_thread_local __declspec(thread)
 660 #  elif defined(__GNUC__) || (defined(_AIX) && (defined(__xlC_ver__) || defined(__ibmxl__)))
 661 #   define _sir_thread_local __thread
 662 #  else
 663 #   if !defined(_CH_) && !defined(__CH__)
 664 #    error "unable to resolve thread local attribute; please contact the developers"
 665 #   endif
 666 #  endif
 667 # endif
 668 
 669 # if defined(__WIN__) && defined(__STDC_SECURE_LIB__)
 670 #  define __HAVE_STDC_SECURE_OR_EXT1__
 671 # elif defined(__STDC_LIB_EXT1__)
 672 #  define __HAVE_STDC_SECURE_OR_EXT1__
 673 # elif defined(__STDC_ALLOC_LIB__)
 674 #  define __HAVE_STDC_EXT2__
 675 # endif
 676 
 677 # if (defined(__clang__) || defined(__GNUC__)) && defined(__FILE_NAME__)
 678 #  define __file__ __FILE_NAME__
 679 # elif defined(__BASE_FILE__)
 680 #  define __file__ __BASE_FILE__
 681 # else
 682 #  define __file__ __FILE__
 683 # endif
 684 
 685 #endif /* !_SIR_PLATFORM_H_INCLUDED */
 686 
 687 #include "sir/impl.h"
 688 
 689 /* Support Clang's -Wdisabled-macro-expansion check on Linux/glibc */
 690 #if defined(SIR_LINT) && (defined(__linux__) && defined(__GLIBC__)) && \
 691     (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) && \
 692     (defined(__clang__) || defined(__clang_version__))
 693 # undef stdin
 694 # undef stdout
 695 # undef stderr
 696 #endif
 697 
 698 /* End of platform.h */

/* [previous][next][first][last][top][bottom][index][help] */