7 #if defined(__FreeBSD__)
8 #include <sys/endian.h>
9 #elif defined(__APPLE__)
10 #include <machine/endian.h>
11 #include <libkern/OSByteOrder.h>
12 #include "compat/bsd-poll.h"
14 #define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
16 #define htobe16(x) OSSwapHostToBigInt16(x)
17 #define htole16(x) OSSwapHostToLittleInt16(x)
18 #define be16toh(x) OSSwapBigToHostInt16(x)
19 #define le16toh(x) OSSwapLittleToHostInt16(x)
21 #define htobe32(x) OSSwapHostToBigInt32(x)
22 #define htole32(x) OSSwapHostToLittleInt32(x)
23 #define be32toh(x) OSSwapBigToHostInt32(x)
24 #define le32toh(x) OSSwapLittleToHostInt32(x)
26 #define htobe64(x) OSSwapHostToBigInt64(x)
27 #define htole64(x) OSSwapHostToLittleInt64(x)
28 #define be64toh(x) OSSwapBigToHostInt64(x)
29 #define le64toh(x) OSSwapLittleToHostInt64(x)
31 #define st_atim st_atimespec
32 #define st_ctim st_ctimespec
33 #define st_mtim st_mtimespec
35 #else /* Linux, etc... */
58 #define flock(fd, op) (0)
64 #define __dead __attribute__ ((__noreturn__))
68 #define pledge(s, p) (0)
69 #define unveil(s, p) (0)
72 #ifndef HAVE_LINUX_LANDLOCK_H
73 #define landlock_no_fs() (0)
75 int landlock_no_fs(void);
83 #include <uuid/uuid.h>
85 #define uuid_s_bad_version 1
86 #define uuid_s_invalid_string_uuid 2
87 #define uuid_s_no_memory 3
89 /* Length of a node address (an IEEE 802 address). */
90 #define _UUID_NODE_LEN 6
95 uint16_t time_hi_and_version;
96 uint8_t clock_seq_hi_and_reserved;
97 uint8_t clock_seq_low;
98 uint8_t node[_UUID_NODE_LEN];
101 int32_t uuid_equal(struct uuid *, struct uuid *, uint32_t *);
102 int32_t uuid_is_nil(struct uuid *, uint32_t *);
103 void uuid_create(uuid_t *, uint32_t *);
104 void uuid_create_nil(struct uuid *, uint32_t *);
105 void uuid_from_string(const char *, uuid_t *, uint32_t *);
106 void uuid_to_string(uuid_t *, char **, uint32_t *);
114 #include <inttypes.h>
118 #include <sys/queue.h>
120 #include "compat/queue.h"
124 #include <sys/tree.h>
126 #include "compat/tree.h"
133 #ifdef HAVE_LIBUTIL_H
139 #include "compat/imsg.h"
145 #include "compat/siphash.h"
148 /* Include Apple-specific headers. Mostly for crypto.*/
149 #if defined(__APPLE__)
150 #define COMMON_DIGEST_FOR_OPENSSL
151 #include <CommonCrypto/CommonDigest.h>
154 #if defined(HAVE_LIBCRYPTO) && !defined(__APPLE__) && !defined(__DragonFly__)
156 #elif !defined(__APPLE__) && !defined(__DragonFly__)
158 #elif defined(__DragonFly__)
159 #include <openssl/sha.h>
162 #if !defined(HAVE_LIBCRYPTO) || defined(__APPLE__) || defined(__DragonFly__)
163 #define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
164 #define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
166 #define SHA1_CTX SHA_CTX
167 #define SHA1Init SHA1_Init
168 #define SHA1Update SHA1_Update
169 #define SHA1Final SHA1_Final
172 #ifndef HAVE_ASPRINTF
174 int asprintf(char **, const char *, ...);
175 int vasprintf(char **, const char *, va_list);
178 #ifndef HAVE_EXPLICIT_BZERO
179 /* explicit_bzero.c */
180 void explicit_bzero(void *, size_t);
183 #ifndef HAVE_GETDTABLECOUNT
184 /* getdtablecount.c */
185 int getdtablecount(void);
188 #ifndef HAVE_CLOSEFROM
193 #if defined (__FreeBSD__)
194 #define closefrom(fd) (closefrom(fd), 0)
199 char *strsep(char **, const char *);
202 #ifndef HAVE_STRTONUM
204 long long strtonum(const char *, long long, long long, const char **);
209 size_t strlcpy(char *, const char *, size_t);
214 size_t strlcat(char *, const char *, size_t);
219 size_t strnlen(const char *, size_t);
224 char *strndup(const char *, size_t);
227 #ifndef HAVE_GETPROGNAME
229 const char *getprogname(void);
234 ssize_t getline(char **, size_t *, FILE *);
237 #ifndef HAVE_FREEZERO
239 void freezero(void *, size_t);
242 #ifndef HAVE_GETDTABLECOUNT
243 /* getdtablecount.c */
244 int getdtablecount(void);
247 #ifndef HAVE_REALLOCARRAY
249 void *reallocarray(void *, size_t, size_t);
252 #ifndef HAVE_RECALLOCARRAY
253 /* recallocarray.c */
254 void *recallocarray(void *, size_t, size_t, size_t);
257 #ifndef HAVE_FMT_SCALED
259 int fmt_scaled(long long, char *);
260 int scan_scaled(char *, long long *);
261 #define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
266 extern int BSDopterr;
267 extern int BSDoptind;
268 extern int BSDoptopt;
269 extern int BSDoptreset;
270 extern char *BSDoptarg;
271 int BSDgetopt(int, char *const *, const char *);
272 #define getopt(ac, av, o) BSDgetopt(ac, av, o)
273 #define opterr BSDopterr
274 #define optind BSDoptind
275 #define optopt BSDoptopt
276 #define optreset BSDoptreset
277 #define optarg BSDoptarg
281 /* Check for some of the non-portable timespec*() functions.
282 * This should largely come from libbsd for systems which
283 * aren't BSD, but this will depend on how old the library
286 #ifndef timespecisset
287 #define timespecisset(tsp) \
288 ((tsp)->tv_sec || (tsp)->tv_nsec)
292 #define timespecsub(tsp, usp, vsp) \
294 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
295 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
296 if ((vsp)->tv_nsec < 0) { \
298 (vsp)->tv_nsec += 1000000000L; \
304 #define timespeccmp(tvp, uvp, cmp) \
305 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
306 ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \
307 ((tvp)->tv_sec cmp (uvp)->tv_sec))
310 #ifndef HAVE_BSD_MERGESORT
312 int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));