diff options
Diffstat (limited to 'freebsd-compat.h')
-rw-r--r-- | freebsd-compat.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/freebsd-compat.h b/freebsd-compat.h new file mode 100644 index 0000000..5e39c5a --- /dev/null +++ b/freebsd-compat.h @@ -0,0 +1,42 @@ +#pragma once + +#define _GNU_SOURCE + +#include <stdint.h> + +#include <sys/param.h> +// 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 <sys/param.h>. +#define nitems(x) (sizeof((x))/sizeof((x)[0])) + +// This is used as the size of the write buffer of sectors. +#define MAXPHYS (1024 * 1024) + +//#define static_assert _Static_assert + +// TODO: do we actually want this, or should we live without? +#define SIGINFO SIGUSR2 + + +// On glibc, these headers use `__unused` as an identifier, so drag them in +// first. +#include <sys/stat.h> +#if __has_include(<sys/sysctl.h>) +#include <sys/sysctl.h> +#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 <errno.h> +static inline char* getprogname() { return program_invocation_short_name; } +#endif |