#pragma once #define _GNU_SOURCE #include #include // Ensure we use a BSD powerof2 that works in static_assert (unlike glibc's). #undef powerof2 #define powerof2(x) ((((x)-1)&(x))==0) // This is in BSD's . #define nitems(x) (sizeof((x))/sizeof((x)[0])) // This is used as the size of the write buffer of sectors. #define MAXPHYS (1024 * 1024) // On glibc, these headers use `__unused` as an identifier, so drag them in // first. #include #if __has_include() #include #endif // Bionic, like the BSDs, has __unused. glibc doesn't. #if defined(__GLIBC__) #define __unused __attribute__((__unused__)) #endif // Neither macOS nor glibc has __packed. #if defined(__APPLE__) || defined(__GLIBC__) #define __packed __attribute__((__packed__)) #endif // The BSDs (including Android and macOS) have getprogname(), but glibc doesn't. #if defined(__GLIBC__) #include static inline char* getprogname() { return program_invocation_short_name; } #endif