// SPDX-License-Identifier: GPL-3.0-or-later // Copyright (C) 2026 Andrea Mazzoleni #ifndef __PORTABLE_H #define __PORTABLE_H #if HAVE_CONFIG_H #include "config.h" /* Use " to include first in the same directory of this file */ #endif /***************************************************************************/ /* Config */ #ifdef __MINGW32__ /** * Enable the GNU printf functions instead of using the MSVCRT ones. * * Note that this is the default if _POSIX is also defined. * To disable it you have to set it to 0. */ #define __USE_MINGW_ANSI_STDIO 1 /** * Define the MSVCRT version targeting Windows 7. */ #define __MSVCRT_VERSION__ 0x0601 /** * Include Windows 7 headers. * * Like for InitializeCriticalSection(). */ #define _WIN32_WINNT 0x601 /** * Enable the rand_s() function. */ #define _CRT_RAND_S /** * Undef as it clashes with windows.h declarations */ #undef DATADIR #include #endif /** * Specify the format attribute for printf. */ #ifdef __MINGW32__ #if defined(__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO == 1 #define attribute_printf gnu_printf /* GNU format */ #define printf(...) __mingw_printf(__VA_ARGS__) /* to support %z in printf */ #else #define attribute_printf ms_printf /* MSVCRT format */ #endif #else #define attribute_printf printf /* GNU format is the default one */ #endif /** * Compiler extension */ #ifndef __always_inline #define __always_inline inline __attribute__((always_inline)) #endif #ifndef __noreturn #define __noreturn __attribute__((noreturn)) #endif /** * Architecture for inline assembly. */ #if HAVE_ASSEMBLY #if defined(__i386__) #define CONFIG_X86 1 #define CONFIG_X86_32 1 #endif #if defined(__x86_64__) #define CONFIG_X86 1 #define CONFIG_X86_64 1 #endif #if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) #define CONFIG_ARM_CRC 1 #endif #endif /** * Includes some platform specific headers. */ #if HAVE_SYS_PARAM_H #include #endif #if HAVE_SYS_MOUNT_H #include #endif #if HAVE_SYS_VFS_H #include #endif #if HAVE_SYS_STATFS_H #include #endif #if HAVE_SYS_FILE_H #include #endif #if HAVE_SYS_SYSCTL_H #include #endif #if HAVE_SYS_IOCTL_H #include #endif #if HAVE_LINUX_FS_H #include #endif #if HAVE_LINUX_BTRFS_H #include #endif #if HAVE_LINUX_FIEMAP_H #include #endif /** * Includes some standard headers. */ #include #include /* On many systems (e.g., Darwin), `stdio.h' is a prerequisite. */ #include #include #include #include #include #include #include #include #if HAVE_STDINT_H #include #endif #if HAVE_INTTYPES_H #include #endif #if HAVE_UNISTD_H #include #endif #if HAVE_ALLOCA_H #include #endif #if TIME_WITH_SYS_TIME #include #include #else #if HAVE_SYS_TIME_H #include #else #include #endif #endif #if HAVE_MACH_MACH_TIME_H #include #endif #if HAVE_DIRENT_H #include #endif #if HAVE_SYS_TYPES_H #include #endif #if HAVE_SYS_MKDEV #include #endif #if HAVE_SYS_SYSMACROS_H #include #endif #if HAVE_SYS_STAT_H #include #endif #if HAVE_SYS_WAIT_H #include #endif #if HAVE_SYS_PRCTL_H #include #endif #if HAVE_GETOPT_H #include #endif #if HAVE_MATH_H #include #endif #if HAVE_EXECINFO_H #include #endif #ifdef HAVE_STRINGS #include #endif #if HAVE_SYSLOG_H #include #endif #if HAVE_GRP_H #include #endif #if HAVE_PWD_H #include #endif #if HAVE_SYS_SYSINFO_H #include #endif #if HAVE_SYS_UTSNAME_H #include #endif #if HAVE_ZLIB #include #endif #if HAVE_ZSTD #include #endif #ifdef __APPLE__ #include #include #include #endif #if HAVE_IO_H #include #endif #if HAVE_GETOPT_LONG #define SWITCH_GETOPT_LONG(a, b) a #else #define SWITCH_GETOPT_LONG(a, b) b #endif /** * Enables lock file support. */ #if (HAVE_FLOCK && HAVE_FTRUNCATE) || defined(_WIN32) #define HAVE_LOCKFILE 1 #endif #ifdef HAVE_LINUX_CLOSE_RANGE_H #include #endif /* * Flags for open() */ #ifndef O_PATH #ifdef O_SEARCH #define O_PATH O_SEARCH /* macOS */ #else #define O_PATH O_RDONLY /* POSIX */ #endif #endif /** * Includes specific support for Windows or Linux. */ #ifdef __MINGW32__ #include "mingw.h" #else #include "unix.h" #endif #endif