1 #pragma once 2 3 #define _GNU_SOURCE 4 5 #include <stdint.h> 6 7 #include <sys/param.h> 8 // Ensure we use a BSD powerof2 that works in static_assert (unlike glibc's). 9 #undef powerof2 10 #define powerof2(x) ((((x)-1)&(x))==0) 11 // This is in BSD's <sys/param.h>. 12 #define nitems(x) (sizeof((x))/sizeof((x)[0])) 13 14 // This is used as the size of the write buffer of sectors. 15 #define MAXPHYS (1024 * 1024) 16 17 // On glibc, these headers use `__unused` as an identifier, so drag them in 18 // first. 19 #include <sys/stat.h> 20 #if __has_include(<sys/sysctl.h>) 21 #include <sys/sysctl.h> 22 #endif 23 // Bionic, like the BSDs, has __unused. glibc doesn't. 24 #if defined(__GLIBC__) 25 #define __unused __attribute__((__unused__)) 26 #endif 27 // Neither macOS nor glibc has __packed. 28 #if defined(__APPLE__) || defined(__GLIBC__) 29 #define __packed __attribute__((__packed__)) 30 #endif 31 32 // The BSDs (including Android and macOS) have getprogname(), but glibc doesn't. 33 #if defined(__GLIBC__) 34 #include <errno.h> getprogname()35static inline char* getprogname() { return program_invocation_short_name; } 36 #endif 37