2 db83f7cf 2023-02-26 thomas * Copyright (c) 2023 Thomas Adam <thomas@xteddy.org>
4 db83f7cf 2023-02-26 thomas * Permission to use, copy, modify, and distribute this software for any
5 db83f7cf 2023-02-26 thomas * purpose with or without fee is hereby granted, provided that the above
6 db83f7cf 2023-02-26 thomas * copyright notice and this permission notice appear in all copies.
8 db83f7cf 2023-02-26 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 db83f7cf 2023-02-26 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 db83f7cf 2023-02-26 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 db83f7cf 2023-02-26 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 db83f7cf 2023-02-26 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 db83f7cf 2023-02-26 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 db83f7cf 2023-02-26 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 dd038bc6 2021-09-21 thomas.ad #ifndef _GOT_COMPAT_H
18 dd038bc6 2021-09-21 thomas.ad #define _GOT_COMPAT_H
20 dd038bc6 2021-09-21 thomas.ad #include <sys/types.h>
21 dd038bc6 2021-09-21 thomas.ad #include <sys/ioctl.h>
22 dd038bc6 2021-09-21 thomas.ad #include <sys/uio.h>
23 92a9e85d 2021-09-24 thomas #if defined(__FreeBSD__)
24 92a9e85d 2021-09-24 thomas #include <sys/endian.h>
25 ef0b17aa 2022-06-24 thomas #include <sys/capsicum.h>
26 d24ddaa6 2022-02-26 thomas #elif defined(__APPLE__)
27 d24ddaa6 2022-02-26 thomas #include <machine/endian.h>
28 d24ddaa6 2022-02-26 thomas #include <libkern/OSByteOrder.h>
29 d24ddaa6 2022-02-26 thomas #include "compat/bsd-poll.h"
31 d24ddaa6 2022-02-26 thomas #define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
33 d24ddaa6 2022-02-26 thomas #define htobe16(x) OSSwapHostToBigInt16(x)
34 d24ddaa6 2022-02-26 thomas #define htole16(x) OSSwapHostToLittleInt16(x)
35 d24ddaa6 2022-02-26 thomas #define be16toh(x) OSSwapBigToHostInt16(x)
36 d24ddaa6 2022-02-26 thomas #define le16toh(x) OSSwapLittleToHostInt16(x)
38 d24ddaa6 2022-02-26 thomas #define htobe32(x) OSSwapHostToBigInt32(x)
39 d24ddaa6 2022-02-26 thomas #define htole32(x) OSSwapHostToLittleInt32(x)
40 d24ddaa6 2022-02-26 thomas #define be32toh(x) OSSwapBigToHostInt32(x)
41 d24ddaa6 2022-02-26 thomas #define le32toh(x) OSSwapLittleToHostInt32(x)
43 d24ddaa6 2022-02-26 thomas #define htobe64(x) OSSwapHostToBigInt64(x)
44 d24ddaa6 2022-02-26 thomas #define htole64(x) OSSwapHostToLittleInt64(x)
45 d24ddaa6 2022-02-26 thomas #define be64toh(x) OSSwapBigToHostInt64(x)
46 d24ddaa6 2022-02-26 thomas #define le64toh(x) OSSwapLittleToHostInt64(x)
48 d24ddaa6 2022-02-26 thomas #define st_atim st_atimespec
49 d24ddaa6 2022-02-26 thomas #define st_ctim st_ctimespec
50 d24ddaa6 2022-02-26 thomas #define st_mtim st_mtimespec
52 d24ddaa6 2022-02-26 thomas #else /* Linux, etc... */
53 92a9e85d 2021-09-24 thomas #include <endian.h>
54 6aa6ad44 2022-07-16 thomas #include <grp.h>
57 dd038bc6 2021-09-21 thomas.ad #include <fnmatch.h>
58 dd038bc6 2021-09-21 thomas.ad #include <limits.h>
59 dd038bc6 2021-09-21 thomas.ad #include <stdio.h>
60 dd038bc6 2021-09-21 thomas.ad #include <stdint.h>
62 dd038bc6 2021-09-21 thomas.ad /* For flock. */
63 dd038bc6 2021-09-21 thomas.ad #ifndef O_EXLOCK
64 dd038bc6 2021-09-21 thomas.ad #define O_EXLOCK 0
67 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_FLOCK
68 dd038bc6 2021-09-21 thomas.ad #define LOCK_SH 0
69 dd038bc6 2021-09-21 thomas.ad #define LOCK_EX 0
70 dd038bc6 2021-09-21 thomas.ad #define LOCK_NB 0
71 dd038bc6 2021-09-21 thomas.ad #define flock(fd, op) (0)
73 dd038bc6 2021-09-21 thomas.ad #include <sys/file.h>
76 21bb1653 2022-07-16 thomas /* POSIX doesn't define WAIT_ANY, so provide it if it's not found. */
77 21bb1653 2022-07-16 thomas #ifndef WAIT_ANY
78 21bb1653 2022-07-16 thomas #define WAIT_ANY (-1)
81 ba107e80 2022-07-16 thomas /* SOCK_NONBLOCK isn't available across BSDs... */
82 ba107e80 2022-07-16 thomas #ifndef SOCK_NONBLOCK
83 ba107e80 2022-07-16 thomas #define SOCK_NONBLOCK 00004000
86 2fcd7106 2022-07-16 thomas /* On FreeBSD (and possibly others), EAI_NODATA was removed, in favour of
87 2fcd7106 2022-07-16 thomas * using EAI_NONAME.
89 2fcd7106 2022-07-16 thomas #ifndef EAI_NODATA
90 2fcd7106 2022-07-16 thomas #define EAI_NODATA EAI_NONAME
93 dd038bc6 2021-09-21 thomas.ad #ifndef __dead
94 dd038bc6 2021-09-21 thomas.ad #define __dead __attribute__ ((__noreturn__))
97 c4e2e0d0 2022-07-16 thomas #ifndef __unused
98 c4e2e0d0 2022-07-16 thomas #define __unused __attribute__ ((__unused__))
101 dd038bc6 2021-09-21 thomas.ad #ifndef __OpenBSD__
102 dd038bc6 2021-09-21 thomas.ad #define pledge(s, p) (0)
103 dd038bc6 2021-09-21 thomas.ad #define unveil(s, p) (0)
106 ef0b17aa 2022-06-24 thomas #ifndef __FreeBSD__
107 5d120ea8 2022-06-23 op #define cap_enter() (0)
110 683ec58e 2022-07-16 thomas #ifndef HAVE_SETRESGID
111 683ec58e 2022-07-16 thomas #define setresgid(a, b, c) (0)
114 683ec58e 2022-07-16 thomas #ifndef HAVE_SETRESUID
115 683ec58e 2022-07-16 thomas #define setresuid(a, b, c) (0)
118 97799ccd 2022-02-06 thomas #ifndef HAVE_LINUX_LANDLOCK_H
119 97799ccd 2022-02-06 thomas #define landlock_no_fs() (0)
121 97799ccd 2022-02-06 thomas int landlock_no_fs(void);
122 dd038bc6 2021-09-21 thomas.ad #endif
124 dd038bc6 2021-09-21 thomas.ad #ifndef INFTIM
125 dd038bc6 2021-09-21 thomas.ad #define INFTIM -1
126 dd038bc6 2021-09-21 thomas.ad #endif
128 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_BSD_UUID
129 dd038bc6 2021-09-21 thomas.ad #include <uuid/uuid.h>
130 dd038bc6 2021-09-21 thomas.ad #define uuid_s_ok 0
131 dd038bc6 2021-09-21 thomas.ad #define uuid_s_bad_version 1
132 dd038bc6 2021-09-21 thomas.ad #define uuid_s_invalid_string_uuid 2
133 dd038bc6 2021-09-21 thomas.ad #define uuid_s_no_memory 3
135 dd038bc6 2021-09-21 thomas.ad /* Length of a node address (an IEEE 802 address). */
136 dd038bc6 2021-09-21 thomas.ad #define _UUID_NODE_LEN 6
138 dd038bc6 2021-09-21 thomas.ad struct uuid {
139 dd038bc6 2021-09-21 thomas.ad uint32_t time_low;
140 dd038bc6 2021-09-21 thomas.ad uint16_t time_mid;
141 dd038bc6 2021-09-21 thomas.ad uint16_t time_hi_and_version;
142 dd038bc6 2021-09-21 thomas.ad uint8_t clock_seq_hi_and_reserved;
143 dd038bc6 2021-09-21 thomas.ad uint8_t clock_seq_low;
144 dd038bc6 2021-09-21 thomas.ad uint8_t node[_UUID_NODE_LEN];
147 dd038bc6 2021-09-21 thomas.ad int32_t uuid_equal(struct uuid *, struct uuid *, uint32_t *);
148 dd038bc6 2021-09-21 thomas.ad int32_t uuid_is_nil(struct uuid *, uint32_t *);
149 dd038bc6 2021-09-21 thomas.ad void uuid_create(uuid_t *, uint32_t *);
150 dd038bc6 2021-09-21 thomas.ad void uuid_create_nil(struct uuid *, uint32_t *);
151 dd038bc6 2021-09-21 thomas.ad void uuid_from_string(const char *, uuid_t *, uint32_t *);
152 dd038bc6 2021-09-21 thomas.ad void uuid_to_string(uuid_t *, char **, uint32_t *);
154 9d70a0bf 2022-02-26 thomas #include <uuid.h>
155 dd038bc6 2021-09-21 thomas.ad #endif
157 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_STDINT_H
158 dd038bc6 2021-09-21 thomas.ad #include <stdint.h>
160 dd038bc6 2021-09-21 thomas.ad #include <inttypes.h>
161 dd038bc6 2021-09-21 thomas.ad #endif
163 46384c6e 2022-09-13 thomas #ifdef HAVE_QUEUE_H
164 19467d59 2022-07-16 thomas #include <sys/queue.h>
165 dd038bc6 2021-09-21 thomas.ad #endif
167 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_TREE_H
168 dd038bc6 2021-09-21 thomas.ad #include <sys/tree.h>
170 dd038bc6 2021-09-21 thomas.ad #include "compat/tree.h"
171 dd038bc6 2021-09-21 thomas.ad #endif
173 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_UTIL_H
174 dd038bc6 2021-09-21 thomas.ad #include <util.h>
175 dd038bc6 2021-09-21 thomas.ad #endif
177 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_LIBUTIL_H
178 dd038bc6 2021-09-21 thomas.ad #include <libutil.h>
179 dd038bc6 2021-09-21 thomas.ad #endif
181 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_IMSG
183 dd038bc6 2021-09-21 thomas.ad #include "compat/imsg.h"
186 ddd12270 2022-04-22 thomas #ifdef HAVE_SIPHASH
187 ddd12270 2022-04-22 thomas #include <siphash.h>
189 ddd12270 2022-04-22 thomas #include "compat/siphash.h"
190 dd038bc6 2021-09-21 thomas.ad #endif
192 81e077a6 2022-03-08 thomas /* Include Apple-specific headers. Mostly for crypto.*/
193 81e077a6 2022-03-08 thomas #if defined(__APPLE__)
194 d24ddaa6 2022-02-26 thomas #define COMMON_DIGEST_FOR_OPENSSL
195 d24ddaa6 2022-02-26 thomas #include <CommonCrypto/CommonDigest.h>
197 b1ec8cee 2023-02-25 thomas #define SHA512_BLOCK_LENGTH 128
198 b1ec8cee 2023-02-25 thomas typedef struct _SHA2_CTX {
200 b1ec8cee 2023-02-25 thomas u_int32_t st32[8];
201 b1ec8cee 2023-02-25 thomas u_int64_t st64[8];
203 b1ec8cee 2023-02-25 thomas u_int64_t bitcount[2];
204 b1ec8cee 2023-02-25 thomas u_int8_t buffer[SHA512_BLOCK_LENGTH];
205 b1ec8cee 2023-02-25 thomas } SHA2_CTX;
206 b1ec8cee 2023-02-25 thomas #define SHA256Init SHA256_Init
207 b1ec8cee 2023-02-25 thomas #define SHA256Update SHA256_Update
208 b1ec8cee 2023-02-25 thomas #define SHA256Final SHA256_Final
211 b1ec8cee 2023-02-25 thomas #ifndef __APPLE__
212 98670ba7 2023-02-23 thomas #ifdef HAVE_SHA_AS_SHA1
213 98670ba7 2023-02-23 thomas # include <sha.h>
215 98670ba7 2023-02-23 thomas #ifdef HAVE_SHA1_AS_SHA1
216 98670ba7 2023-02-23 thomas # include <sha1.h>
218 98670ba7 2023-02-23 thomas #ifdef HAVE_SHA2
219 98670ba7 2023-02-23 thomas # include <sha2.h>
221 b1ec8cee 2023-02-25 thomas # include "sha2.h"
223 98670ba7 2023-02-23 thomas #ifdef HAVE_SHA256
224 98670ba7 2023-02-23 thomas # include <sha256.h>
228 98670ba7 2023-02-23 thomas /* Catch-all for systems where the header files don't exist and/or the below
229 98670ba7 2023-02-23 thomas * still are not defined.
231 98670ba7 2023-02-23 thomas #ifndef SHA256_DIGEST_LENGTH
232 98670ba7 2023-02-23 thomas #define SHA256_DIGEST_LENGTH 32
235 98670ba7 2023-02-23 thomas #ifndef SHA256_DIGEST_STRING_LENGTH
236 98670ba7 2023-02-23 thomas #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
239 98670ba7 2023-02-23 thomas #if defined(__DragonFly__)
240 b26177ad 2022-03-03 thomas #include <openssl/sha.h>
243 98670ba7 2023-02-23 thomas #ifdef NEEDS_SHA1_DEFS
244 92a9e85d 2021-09-24 thomas #define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
245 92a9e85d 2021-09-24 thomas #define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
247 92a9e85d 2021-09-24 thomas #define SHA1_CTX SHA_CTX
248 92a9e85d 2021-09-24 thomas #define SHA1Init SHA1_Init
249 92a9e85d 2021-09-24 thomas #define SHA1Update SHA1_Update
250 92a9e85d 2021-09-24 thomas #define SHA1Final SHA1_Final
254 75716fd6 2022-08-27 thomas * The following SA_LEN/SS_LEN dance comes from various source, notably
255 75716fd6 2022-08-27 thomas * OpenSMTP by way of OpenNTPD and OpenBGPD (thanks everyone!). got-portable
256 75716fd6 2022-08-27 thomas * has tweaked a lot of the following macros to suit the needs of
257 75716fd6 2022-08-27 thomas * got-portable.
260 75716fd6 2022-08-27 thomas /* From OpenNTPD portable */
261 75716fd6 2022-08-27 thomas #if !defined(SA_LEN)
262 75716fd6 2022-08-27 thomas # if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
263 75716fd6 2022-08-27 thomas # define SA_LEN(x) ((x)->sa_len)
265 75716fd6 2022-08-27 thomas # define SA_LEN(x) ((x)->sa_family == AF_INET6 ? \
266 75716fd6 2022-08-27 thomas sizeof(struct sockaddr_in6) : \
267 75716fd6 2022-08-27 thomas sizeof(struct sockaddr_in))
272 75716fd6 2022-08-27 thomas /* From OpenBGPD portable */
273 75716fd6 2022-08-27 thomas #if !defined(SS_LEN)
274 75716fd6 2022-08-27 thomas # if defined(HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN)
275 75716fd6 2022-08-27 thomas # define SS_LEN(x) ((x)->ss_len)
277 75716fd6 2022-08-27 thomas # define SS_LEN(x) SA_LEN((struct sockaddr *)(x))
281 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_ASPRINTF
282 dd038bc6 2021-09-21 thomas.ad /* asprintf.c */
283 dd038bc6 2021-09-21 thomas.ad int asprintf(char **, const char *, ...);
284 dd038bc6 2021-09-21 thomas.ad int vasprintf(char **, const char *, va_list);
285 dd038bc6 2021-09-21 thomas.ad #endif
287 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_EXPLICIT_BZERO
288 dd038bc6 2021-09-21 thomas.ad /* explicit_bzero.c */
289 dd038bc6 2021-09-21 thomas.ad void explicit_bzero(void *, size_t);
290 dd038bc6 2021-09-21 thomas.ad #endif
292 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_GETDTABLECOUNT
293 dd038bc6 2021-09-21 thomas.ad /* getdtablecount.c */
294 dd038bc6 2021-09-21 thomas.ad int getdtablecount(void);
295 dd038bc6 2021-09-21 thomas.ad #endif
297 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_CLOSEFROM
298 dd038bc6 2021-09-21 thomas.ad /* closefrom.c */
299 d24ddaa6 2022-02-26 thomas void closefrom(int);
300 dd038bc6 2021-09-21 thomas.ad #endif
302 92a9e85d 2021-09-24 thomas #if defined (__FreeBSD__)
303 92a9e85d 2021-09-24 thomas #define closefrom(fd) (closefrom(fd), 0)
306 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRSEP
307 dd038bc6 2021-09-21 thomas.ad /* strsep.c */
308 dd038bc6 2021-09-21 thomas.ad char *strsep(char **, const char *);
309 dd038bc6 2021-09-21 thomas.ad #endif
311 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRTONUM
312 dd038bc6 2021-09-21 thomas.ad /* strtonum.c */
313 dd038bc6 2021-09-21 thomas.ad long long strtonum(const char *, long long, long long, const char **);
314 dd038bc6 2021-09-21 thomas.ad #endif
316 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRLCPY
317 dd038bc6 2021-09-21 thomas.ad /* strlcpy.c */
318 dd038bc6 2021-09-21 thomas.ad size_t strlcpy(char *, const char *, size_t);
319 dd038bc6 2021-09-21 thomas.ad #endif
321 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRLCAT
322 dd038bc6 2021-09-21 thomas.ad /* strlcat.c */
323 dd038bc6 2021-09-21 thomas.ad size_t strlcat(char *, const char *, size_t);
324 dd038bc6 2021-09-21 thomas.ad #endif
326 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRNLEN
327 dd038bc6 2021-09-21 thomas.ad /* strnlen.c */
328 dd038bc6 2021-09-21 thomas.ad size_t strnlen(const char *, size_t);
329 dd038bc6 2021-09-21 thomas.ad #endif
331 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRNDUP
332 dd038bc6 2021-09-21 thomas.ad /* strndup.c */
333 dd038bc6 2021-09-21 thomas.ad char *strndup(const char *, size_t);
334 dd038bc6 2021-09-21 thomas.ad #endif
336 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_GETPROGNAME
337 dd038bc6 2021-09-21 thomas.ad /* getprogname.c */
338 dd038bc6 2021-09-21 thomas.ad const char *getprogname(void);
339 dd038bc6 2021-09-21 thomas.ad #endif
341 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_GETLINE
342 dd038bc6 2021-09-21 thomas.ad /* getline.c */
343 dd038bc6 2021-09-21 thomas.ad ssize_t getline(char **, size_t *, FILE *);
344 dd038bc6 2021-09-21 thomas.ad #endif
346 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_FREEZERO
347 dd038bc6 2021-09-21 thomas.ad /* freezero.c */
348 dd038bc6 2021-09-21 thomas.ad void freezero(void *, size_t);
349 dd038bc6 2021-09-21 thomas.ad #endif
351 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_GETDTABLECOUNT
352 dd038bc6 2021-09-21 thomas.ad /* getdtablecount.c */
353 dd038bc6 2021-09-21 thomas.ad int getdtablecount(void);
354 dd038bc6 2021-09-21 thomas.ad #endif
356 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_REALLOCARRAY
357 dd038bc6 2021-09-21 thomas.ad /* reallocarray.c */
358 dd038bc6 2021-09-21 thomas.ad void *reallocarray(void *, size_t, size_t);
359 dd038bc6 2021-09-21 thomas.ad #endif
361 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_RECALLOCARRAY
362 dd038bc6 2021-09-21 thomas.ad /* recallocarray.c */
363 dd038bc6 2021-09-21 thomas.ad void *recallocarray(void *, size_t, size_t, size_t);
364 dd038bc6 2021-09-21 thomas.ad #endif
366 c4e2e0d0 2022-07-16 thomas #ifndef HAVE_SETPROCTITLE
367 c4e2e0d0 2022-07-16 thomas /* setproctitle.c */
368 c4e2e0d0 2022-07-16 thomas void setproctitle(const char *, ...);
371 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_FMT_SCALED
372 dd038bc6 2021-09-21 thomas.ad /* fmt_scaled.c */
373 dd038bc6 2021-09-21 thomas.ad int fmt_scaled(long long, char *);
374 dd038bc6 2021-09-21 thomas.ad int scan_scaled(char *, long long *);
375 dd038bc6 2021-09-21 thomas.ad #define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
376 dd038bc6 2021-09-21 thomas.ad #endif
378 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_LIBBSD
379 dd038bc6 2021-09-21 thomas.ad /* getopt.c */
380 dd038bc6 2021-09-21 thomas.ad extern int BSDopterr;
381 dd038bc6 2021-09-21 thomas.ad extern int BSDoptind;
382 dd038bc6 2021-09-21 thomas.ad extern int BSDoptopt;
383 dd038bc6 2021-09-21 thomas.ad extern int BSDoptreset;
384 dd038bc6 2021-09-21 thomas.ad extern char *BSDoptarg;
385 dd038bc6 2021-09-21 thomas.ad int BSDgetopt(int, char *const *, const char *);
386 dd038bc6 2021-09-21 thomas.ad #define getopt(ac, av, o) BSDgetopt(ac, av, o)
387 dd038bc6 2021-09-21 thomas.ad #define opterr BSDopterr
388 dd038bc6 2021-09-21 thomas.ad #define optind BSDoptind
389 dd038bc6 2021-09-21 thomas.ad #define optopt BSDoptopt
390 dd038bc6 2021-09-21 thomas.ad #define optreset BSDoptreset
391 dd038bc6 2021-09-21 thomas.ad #define optarg BSDoptarg
392 dd038bc6 2021-09-21 thomas.ad #endif
393 dd038bc6 2021-09-21 thomas.ad #endif
395 de1dbfe9 2022-01-05 thomas /* Check for some of the non-portable timespec*() functions.
396 de1dbfe9 2022-01-05 thomas * This should largely come from libbsd for systems which
397 de1dbfe9 2022-01-05 thomas * aren't BSD, but this will depend on how old the library
400 de1dbfe9 2022-01-05 thomas #ifndef timespecisset
401 de1dbfe9 2022-01-05 thomas #define timespecisset(tsp) \
402 de1dbfe9 2022-01-05 thomas ((tsp)->tv_sec || (tsp)->tv_nsec)
405 de1dbfe9 2022-01-05 thomas #ifndef timespecsub
406 de1dbfe9 2022-01-05 thomas #define timespecsub(tsp, usp, vsp) \
408 de1dbfe9 2022-01-05 thomas (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
409 de1dbfe9 2022-01-05 thomas (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
410 de1dbfe9 2022-01-05 thomas if ((vsp)->tv_nsec < 0) { \
411 de1dbfe9 2022-01-05 thomas (vsp)->tv_sec--; \
412 de1dbfe9 2022-01-05 thomas (vsp)->tv_nsec += 1000000000L; \
414 de1dbfe9 2022-01-05 thomas } while (0)
417 de1dbfe9 2022-01-05 thomas #ifndef timespeccmp
418 de1dbfe9 2022-01-05 thomas #define timespeccmp(tvp, uvp, cmp) \
419 de1dbfe9 2022-01-05 thomas (((tvp)->tv_sec == (uvp)->tv_sec) ? \
420 de1dbfe9 2022-01-05 thomas ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \
421 de1dbfe9 2022-01-05 thomas ((tvp)->tv_sec cmp (uvp)->tv_sec))
424 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_BSD_MERGESORT
425 dd038bc6 2021-09-21 thomas.ad /* mergesort.c */
426 dd038bc6 2021-09-21 thomas.ad int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
427 dd038bc6 2021-09-21 thomas.ad #endif