You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.0 KiB
37 lines
1.0 KiB
4 months ago
|
#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)
|
||
|
|
||
|
// 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
|