// Copyright (c) 2018-2026 Jean-Philippe Bruyère // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) #pragma once #include // cross platform os helpers #if defined(_WIN32) || defined(_WIN64) // disable warning on iostream functions on windows #define _CRT_SECURE_NO_WARNINGS #include #include #if defined(_WIN64) #ifndef isnan #define isnan _isnanf #endif #endif #define vkvg_inline __forceinline #define disable_warning (warn) #define reset_warning (warn) #elif __APPLE__ #include #include #include #include #define vkvg_inline static #define disable_warning (warn) #define reset_warning (warn) #elif __unix__ #include #include #include #include #define vkvg_inline static inline __attribute((always_inline)) #define disable_warning (warn) #pragma GCC diagnostic ignored "-W" #warn #define reset_warning (warn) #pragma GCC diagnostic warning "-W" #warn #if __linux__ void _linux_register_error_handler(); #endif #endif #if defined(__clang__) #define DIAGNOSTIC_DISABLE_UNUSED _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Wunused-function\"") #define DIAGNOSTIC_RESTORE_UNUSED _Pragma("clang diagnostic pop") #elif defined(__GNUC__) #define DIAGNOSTIC_DISABLE_UNUSED _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wunused-function\"") #define DIAGNOSTIC_RESTORE_UNUSED _Pragma("GCC diagnostic pop") #elif defined(_MSC_VER) #define DIAGNOSTIC_DISABLE_UNUSED __pragma(warning(push)) \ __pragma(warning(disable : 4505)) #define DIAGNOSTIC_RESTORE_UNUSED __pragma(warning(pop)) #else #define DIAGNOSTIC_DISABLE_UNUSED #define DIAGNOSTIC_RESTORE_UNUSED #endif #if defined(__GNUC__) || defined(__clang__) /* GCC and Clang (Linux, macOS, MinGW) */ #define vkvg_likely(x) __builtin_expect(!!(x), 1) #define vkvg_unlikely(x) __builtin_expect(!!(x), 0) #elif defined(_MSC_VER) /* MSVC (Windows) */ /* MSVC does not have a static branch predictor builtin. */ /* We fall back to standard evaluation. MSVC relies on PGO */ /* (Profile-Guided Optimization) to sort branches at link time. */ #define vkvg_likely(x) (!!(x)) #define vkvg_unlikely(x) (!!(x)) #else /* Fallback for any other exotic compiler */ #define vkvg_likely(x) (!!(x)) #define vkvg_unlikely(x) (!!(x)) #endif // 1. Check if we are in a POSIX environment that supports strncasecmp #if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) #include /* Provides the native strncasecmp */ #elif !defined(__APPLE__) /* 2. Fallback: Implement our own C11-compliant version */ #include static inline int strncasecmp(const char *s1, const char *s2, size_t n) { while (n-- > 0) { unsigned char u1 = (unsigned char)*s1; unsigned char u2 = (unsigned char)*s2; int diff = tolower(u1) - tolower(u2); if (diff != 0 || u1 == '\0') return diff; s1++; s2++; } return 0; } #endif const char* getUserDir(); int create_dir(const char* path); int create_dir_tree(const char* path);