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