Platform.h#

Fully qualified name: carb/Platform.h

File members: carb/Platform.h

// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
//
// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
// property and proprietary rights in and to this material, related
// documentation and any modifications thereto. Any use, reproduction,
// disclosure or distribution of this material and related documentation
// without an express license agreement from NVIDIA CORPORATION or
// its affiliates is strictly prohibited.

#pragma once

#define CARB_UNSUPPORTED_PLATFORM() static_assert(false, "Unsupported platform!")

// Platform defines
#ifdef DOXYGEN_BUILD
#    define CARB_PLATFORM_WINDOWS 0
#    define CARB_PLATFORM_LINUX 1
#    define CARB_PLATFORM_MACOS 0
#    define CARB_PLATFORM_NAME
#elif defined(CARB_PLATFORM_WINDOWS) && defined(CARB_PLATFORM_LINUX) && defined(CARB_PLATFORM_MACOS)
#    if (!!CARB_PLATFORM_WINDOWS) + (!!CARB_PLATFORM_LINUX) + (!!CARB_PLATFORM_MACOS) != 1
#        define CARB_PLATFORM_WINDOWS // show previous definition
#        define CARB_PLATFORM_LINUX // show previous definition
#        define CARB_PLATFORM_MACOS // show previous definition
#        error Exactly one of CARB_PLATFORM_WINDOWS, CARB_PLATFORM_LINUX or CARB_PLATFORM_MACOS must be non-zero.
#    endif
#elif !defined(CARB_PLATFORM_WINDOWS) && !defined(CARB_PLATFORM_LINUX)
#    ifdef _WIN32
#        define CARB_PLATFORM_WINDOWS 1
#        define CARB_PLATFORM_LINUX 0
#        define CARB_PLATFORM_MACOS 0
#        define CARB_PLATFORM_NAME "windows"
#    elif defined(__linux__)
#        define CARB_PLATFORM_WINDOWS 0
#        define CARB_PLATFORM_LINUX 1
#        define CARB_PLATFORM_MACOS 0
#        define CARB_PLATFORM_NAME "linux"
#    else
CARB_UNSUPPORTED_PLATFORM();
#    endif
#else
#    error "Must define all of CARB_PLATFORM_WINDOWS, CARB_PLATFORM_LINUX and CARB_PLATFORM_MACOS or none."
#endif

#if CARB_PLATFORM_LINUX || defined(DOXYGEN_BUILD)
#    include <unistd.h> // _POSIX_VERSION comes from unistd.h
#    include <string.h> // for strerror()

#    define CARB_POSIX _POSIX_VERSION
#else
#    define CARB_POSIX 0
#endif

#if !CARB_POSIX || defined(DOXYGEN_BUILD)
#    define CARB_RETRY_EINTR(op) (op)
#else
#    include <cerrno>
#    define CARB_RETRY_EINTR(op)                                                                                       \
        [&] {                                                                                                          \
            decltype(op) ret_;                                                                                         \
            while ((ret_ = (op)) < 0 && errno == EINTR)                                                                \
                ;                                                                                                      \
            return ret_;                                                                                               \
        }()
#endif