7 #if defined(__FreeBSD__)
8 #include <sys/endian.h>
9 #include <sys/capsicum.h>
10 #elif defined(__APPLE__)
11 #include <machine/endian.h>
12 #include <libkern/OSByteOrder.h>
13 #include "compat/bsd-poll.h"
15 #define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
17 #define htobe16(x) OSSwapHostToBigInt16(x)
18 #define htole16(x) OSSwapHostToLittleInt16(x)
19 #define be16toh(x) OSSwapBigToHostInt16(x)
20 #define le16toh(x) OSSwapLittleToHostInt16(x)
22 #define htobe32(x) OSSwapHostToBigInt32(x)
23 #define htole32(x) OSSwapHostToLittleInt32(x)
24 #define be32toh(x) OSSwapBigToHostInt32(x)
25 #define le32toh(x) OSSwapLittleToHostInt32(x)
27 #define htobe64(x) OSSwapHostToBigInt64(x)
28 #define htole64(x) OSSwapHostToLittleInt64(x)
29 #define be64toh(x) OSSwapBigToHostInt64(x)
30 #define le64toh(x) OSSwapLittleToHostInt64(x)
32 #define st_atim st_atimespec
33 #define st_ctim st_ctimespec
34 #define st_mtim st_mtimespec
36 #else /* Linux, etc... */
54 #define flock(fd, op) (0)
59 /* POSIX doesn't define WAIT_ANY, so provide it if it's not found. */
64 /* SOCK_NONBLOCK isn't available across BSDs... */
66 #define SOCK_NONBLOCK 00004000
70 #define __dead __attribute__ ((__noreturn__))
74 #define __unused __attribute__ ((__unused__))
78 #define pledge(s, p) (0)
79 #define unveil(s, p) (0)
83 #define cap_enter() (0)
86 #ifndef HAVE_LINUX_LANDLOCK_H
87 #define landlock_no_fs() (0)
89 int landlock_no_fs(void);
97 #include <uuid/uuid.h>
99 #define uuid_s_bad_version 1
100 #define uuid_s_invalid_string_uuid 2
101 #define uuid_s_no_memory 3
103 /* Length of a node address (an IEEE 802 address). */
104 #define _UUID_NODE_LEN 6
109 uint16_t time_hi_and_version;
110 uint8_t clock_seq_hi_and_reserved;
111 uint8_t clock_seq_low;
112 uint8_t node[_UUID_NODE_LEN];
115 int32_t uuid_equal(struct uuid *, struct uuid *, uint32_t *);
116 int32_t uuid_is_nil(struct uuid *, uint32_t *);
117 void uuid_create(uuid_t *, uint32_t *);
118 void uuid_create_nil(struct uuid *, uint32_t *);
119 void uuid_from_string(const char *, uuid_t *, uint32_t *);
120 void uuid_to_string(uuid_t *, char **, uint32_t *);
128 #include <inttypes.h>
132 #include <sys/queue.h>
134 #include "compat/queue.h"
138 #include <sys/tree.h>
140 #include "compat/tree.h"
147 #ifdef HAVE_LIBUTIL_H
153 #include "compat/imsg.h"
159 #include "compat/siphash.h"
162 /* Include Apple-specific headers. Mostly for crypto.*/
163 #if defined(__APPLE__)
164 #define COMMON_DIGEST_FOR_OPENSSL
165 #include <CommonCrypto/CommonDigest.h>
168 #if defined(HAVE_LIBCRYPTO) && !defined(__APPLE__) && !defined(__DragonFly__)
170 #elif !defined(__APPLE__) && !defined(__DragonFly__)
172 #elif defined(__DragonFly__)
173 #include <openssl/sha.h>
176 #if !defined(HAVE_LIBCRYPTO) || defined(__APPLE__) || defined(__DragonFly__)
177 #define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
178 #define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
180 #define SHA1_CTX SHA_CTX
181 #define SHA1Init SHA1_Init
182 #define SHA1Update SHA1_Update
183 #define SHA1Final SHA1_Final
186 #ifndef HAVE_ASPRINTF
188 int asprintf(char **, const char *, ...);
189 int vasprintf(char **, const char *, va_list);
192 #ifndef HAVE_EXPLICIT_BZERO
193 /* explicit_bzero.c */
194 void explicit_bzero(void *, size_t);
197 #ifndef HAVE_GETDTABLECOUNT
198 /* getdtablecount.c */
199 int getdtablecount(void);
202 #ifndef HAVE_CLOSEFROM
207 #if defined (__FreeBSD__)
208 #define closefrom(fd) (closefrom(fd), 0)
213 char *strsep(char **, const char *);
216 #ifndef HAVE_STRTONUM
218 long long strtonum(const char *, long long, long long, const char **);
223 size_t strlcpy(char *, const char *, size_t);
228 size_t strlcat(char *, const char *, size_t);
233 size_t strnlen(const char *, size_t);
238 char *strndup(const char *, size_t);
241 #ifndef HAVE_GETPROGNAME
243 const char *getprogname(void);
248 ssize_t getline(char **, size_t *, FILE *);
251 #ifndef HAVE_FREEZERO
253 void freezero(void *, size_t);
256 #ifndef HAVE_GETDTABLECOUNT
257 /* getdtablecount.c */
258 int getdtablecount(void);
261 #ifndef HAVE_REALLOCARRAY
263 void *reallocarray(void *, size_t, size_t);
266 #ifndef HAVE_RECALLOCARRAY
267 /* recallocarray.c */
268 void *recallocarray(void *, size_t, size_t, size_t);
271 #ifndef HAVE_SETPROCTITLE
273 void setproctitle(const char *, ...);
276 #ifndef HAVE_FMT_SCALED
278 int fmt_scaled(long long, char *);
279 int scan_scaled(char *, long long *);
280 #define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
285 extern int BSDopterr;
286 extern int BSDoptind;
287 extern int BSDoptopt;
288 extern int BSDoptreset;
289 extern char *BSDoptarg;
290 int BSDgetopt(int, char *const *, const char *);
291 #define getopt(ac, av, o) BSDgetopt(ac, av, o)
292 #define opterr BSDopterr
293 #define optind BSDoptind
294 #define optopt BSDoptopt
295 #define optreset BSDoptreset
296 #define optarg BSDoptarg
300 /* Check for some of the non-portable timespec*() functions.
301 * This should largely come from libbsd for systems which
302 * aren't BSD, but this will depend on how old the library
305 #ifndef timespecisset
306 #define timespecisset(tsp) \
307 ((tsp)->tv_sec || (tsp)->tv_nsec)
311 #define timespecsub(tsp, usp, vsp) \
313 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
314 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
315 if ((vsp)->tv_nsec < 0) { \
317 (vsp)->tv_nsec += 1000000000L; \
323 #define timespeccmp(tvp, uvp, cmp) \
324 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
325 ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \
326 ((tvp)->tv_sec cmp (uvp)->tv_sec))
329 #ifndef HAVE_BSD_MERGESORT
331 int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));