• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 and musl don't.
24 #if defined(__GLIBC__) || defined(ANDROID_HOST_MUSL)
25 #define __unused __attribute__((__unused__))
26 #endif
27 // Neither macOS, glibc nor musl has __packed.
28 #if defined(__APPLE__) || defined(__GLIBC__) || defined(ANDROID_HOST_MUSL)
29 #define __packed __attribute__((__packed__))
30 #endif
31 
32 // The BSDs (including Android and macOS) have getprogname(), but glibc and musl don't.
33 #if defined(__GLIBC__) || defined(ANDROID_HOST_MUSL)
34 #include <errno.h>
getprogname()35 static inline char* getprogname() { return program_invocation_short_name; }
36 #endif
37