Blame


1 dd038bc6 2021-09-21 thomas.ad #ifndef _GOT_COMPAT_H
2 dd038bc6 2021-09-21 thomas.ad #define _GOT_COMPAT_H
3 dd038bc6 2021-09-21 thomas.ad
4 dd038bc6 2021-09-21 thomas.ad #include <sys/types.h>
5 dd038bc6 2021-09-21 thomas.ad #include <sys/ioctl.h>
6 dd038bc6 2021-09-21 thomas.ad #include <sys/uio.h>
7 92a9e85d 2021-09-24 thomas #if defined(__FreeBSD__)
8 92a9e85d 2021-09-24 thomas #include <sys/endian.h>
9 ef0b17aa 2022-06-24 thomas #include <sys/capsicum.h>
10 d24ddaa6 2022-02-26 thomas #elif defined(__APPLE__)
11 d24ddaa6 2022-02-26 thomas #include <machine/endian.h>
12 d24ddaa6 2022-02-26 thomas #include <libkern/OSByteOrder.h>
13 d24ddaa6 2022-02-26 thomas #include "compat/bsd-poll.h"
14 d24ddaa6 2022-02-26 thomas
15 d24ddaa6 2022-02-26 thomas #define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
16 d24ddaa6 2022-02-26 thomas
17 d24ddaa6 2022-02-26 thomas #define htobe16(x) OSSwapHostToBigInt16(x)
18 d24ddaa6 2022-02-26 thomas #define htole16(x) OSSwapHostToLittleInt16(x)
19 d24ddaa6 2022-02-26 thomas #define be16toh(x) OSSwapBigToHostInt16(x)
20 d24ddaa6 2022-02-26 thomas #define le16toh(x) OSSwapLittleToHostInt16(x)
21 d24ddaa6 2022-02-26 thomas
22 d24ddaa6 2022-02-26 thomas #define htobe32(x) OSSwapHostToBigInt32(x)
23 d24ddaa6 2022-02-26 thomas #define htole32(x) OSSwapHostToLittleInt32(x)
24 d24ddaa6 2022-02-26 thomas #define be32toh(x) OSSwapBigToHostInt32(x)
25 d24ddaa6 2022-02-26 thomas #define le32toh(x) OSSwapLittleToHostInt32(x)
26 d24ddaa6 2022-02-26 thomas
27 d24ddaa6 2022-02-26 thomas #define htobe64(x) OSSwapHostToBigInt64(x)
28 d24ddaa6 2022-02-26 thomas #define htole64(x) OSSwapHostToLittleInt64(x)
29 d24ddaa6 2022-02-26 thomas #define be64toh(x) OSSwapBigToHostInt64(x)
30 d24ddaa6 2022-02-26 thomas #define le64toh(x) OSSwapLittleToHostInt64(x)
31 d24ddaa6 2022-02-26 thomas
32 d24ddaa6 2022-02-26 thomas #define st_atim st_atimespec
33 d24ddaa6 2022-02-26 thomas #define st_ctim st_ctimespec
34 d24ddaa6 2022-02-26 thomas #define st_mtim st_mtimespec
35 d24ddaa6 2022-02-26 thomas
36 d24ddaa6 2022-02-26 thomas #else /* Linux, etc... */
37 92a9e85d 2021-09-24 thomas #include <endian.h>
38 92a9e85d 2021-09-24 thomas #endif
39 dd038bc6 2021-09-21 thomas.ad
40 dd038bc6 2021-09-21 thomas.ad #include <fnmatch.h>
41 dd038bc6 2021-09-21 thomas.ad #include <limits.h>
42 dd038bc6 2021-09-21 thomas.ad #include <stdio.h>
43 dd038bc6 2021-09-21 thomas.ad #include <stdint.h>
44 dd038bc6 2021-09-21 thomas.ad
45 dd038bc6 2021-09-21 thomas.ad /* For flock. */
46 dd038bc6 2021-09-21 thomas.ad #ifndef O_EXLOCK
47 dd038bc6 2021-09-21 thomas.ad #define O_EXLOCK 0
48 dd038bc6 2021-09-21 thomas.ad #endif
49 dd038bc6 2021-09-21 thomas.ad
50 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_FLOCK
51 dd038bc6 2021-09-21 thomas.ad #define LOCK_SH 0
52 dd038bc6 2021-09-21 thomas.ad #define LOCK_EX 0
53 dd038bc6 2021-09-21 thomas.ad #define LOCK_NB 0
54 dd038bc6 2021-09-21 thomas.ad #define flock(fd, op) (0)
55 dd038bc6 2021-09-21 thomas.ad #else
56 dd038bc6 2021-09-21 thomas.ad #include <sys/file.h>
57 dd038bc6 2021-09-21 thomas.ad #endif
58 dd038bc6 2021-09-21 thomas.ad
59 0ada29ea 2022-07-14 thomas /* POSIX doesn't define WAIT_ANY, so provide it if it's not found. */
60 0ada29ea 2022-07-14 thomas #ifndef WAIT_ANY
61 0ada29ea 2022-07-14 thomas #define WAIT_ANY (-1)
62 0ada29ea 2022-07-14 thomas #endif
63 0ada29ea 2022-07-14 thomas
64 3413106e 2022-07-15 thomas /* SOCK_NONBLOCK isn't available across BSDs... */
65 3413106e 2022-07-15 thomas #ifndef SOCK_NONBLOCK
66 3413106e 2022-07-15 thomas #define SOCK_NONBLOCK 00004000
67 3413106e 2022-07-15 thomas #endif
68 3413106e 2022-07-15 thomas
69 8baf059b 2022-07-15 thomas /* On FreeBSD (and possibly others), EAI_NODATA was removed, in favour of
70 8baf059b 2022-07-15 thomas * using EAI_NONAME.
71 8baf059b 2022-07-15 thomas */
72 8baf059b 2022-07-15 thomas #ifndef EAI_NODATA
73 8baf059b 2022-07-15 thomas #define EAI_NODATA EAI_NONAME
74 8baf059b 2022-07-15 thomas #endif
75 8baf059b 2022-07-15 thomas
76 dd038bc6 2021-09-21 thomas.ad #ifndef __dead
77 dd038bc6 2021-09-21 thomas.ad #define __dead __attribute__ ((__noreturn__))
78 685f4593 2022-07-15 thomas #endif
79 685f4593 2022-07-15 thomas
80 685f4593 2022-07-15 thomas #ifndef __unused
81 685f4593 2022-07-15 thomas #define __unused __attribute__ ((__unused__))
82 dd038bc6 2021-09-21 thomas.ad #endif
83 dd038bc6 2021-09-21 thomas.ad
84 dd038bc6 2021-09-21 thomas.ad #ifndef __OpenBSD__
85 dd038bc6 2021-09-21 thomas.ad #define pledge(s, p) (0)
86 dd038bc6 2021-09-21 thomas.ad #define unveil(s, p) (0)
87 5d120ea8 2022-06-23 op #endif
88 5d120ea8 2022-06-23 op
89 ef0b17aa 2022-06-24 thomas #ifndef __FreeBSD__
90 5d120ea8 2022-06-23 op #define cap_enter() (0)
91 b7ec5831 2022-07-15 thomas #endif
92 b7ec5831 2022-07-15 thomas
93 b7ec5831 2022-07-15 thomas #ifndef HAVE_SETRESGID
94 b7ec5831 2022-07-15 thomas #define setresgid(a, b, c) (0)
95 b7ec5831 2022-07-15 thomas #endif
96 b7ec5831 2022-07-15 thomas
97 b7ec5831 2022-07-15 thomas #ifndef HAVE_SETRESUID
98 b7ec5831 2022-07-15 thomas #define setresuid(a, b, c) (0)
99 97799ccd 2022-02-06 thomas #endif
100 97799ccd 2022-02-06 thomas
101 97799ccd 2022-02-06 thomas #ifndef HAVE_LINUX_LANDLOCK_H
102 97799ccd 2022-02-06 thomas #define landlock_no_fs() (0)
103 97799ccd 2022-02-06 thomas #else
104 97799ccd 2022-02-06 thomas int landlock_no_fs(void);
105 dd038bc6 2021-09-21 thomas.ad #endif
106 dd038bc6 2021-09-21 thomas.ad
107 dd038bc6 2021-09-21 thomas.ad #ifndef INFTIM
108 dd038bc6 2021-09-21 thomas.ad #define INFTIM -1
109 dd038bc6 2021-09-21 thomas.ad #endif
110 dd038bc6 2021-09-21 thomas.ad
111 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_BSD_UUID
112 dd038bc6 2021-09-21 thomas.ad #include <uuid/uuid.h>
113 dd038bc6 2021-09-21 thomas.ad #define uuid_s_ok 0
114 dd038bc6 2021-09-21 thomas.ad #define uuid_s_bad_version 1
115 dd038bc6 2021-09-21 thomas.ad #define uuid_s_invalid_string_uuid 2
116 dd038bc6 2021-09-21 thomas.ad #define uuid_s_no_memory 3
117 dd038bc6 2021-09-21 thomas.ad
118 dd038bc6 2021-09-21 thomas.ad /* Length of a node address (an IEEE 802 address). */
119 dd038bc6 2021-09-21 thomas.ad #define _UUID_NODE_LEN 6
120 dd038bc6 2021-09-21 thomas.ad
121 dd038bc6 2021-09-21 thomas.ad struct uuid {
122 dd038bc6 2021-09-21 thomas.ad uint32_t time_low;
123 dd038bc6 2021-09-21 thomas.ad uint16_t time_mid;
124 dd038bc6 2021-09-21 thomas.ad uint16_t time_hi_and_version;
125 dd038bc6 2021-09-21 thomas.ad uint8_t clock_seq_hi_and_reserved;
126 dd038bc6 2021-09-21 thomas.ad uint8_t clock_seq_low;
127 dd038bc6 2021-09-21 thomas.ad uint8_t node[_UUID_NODE_LEN];
128 dd038bc6 2021-09-21 thomas.ad };
129 dd038bc6 2021-09-21 thomas.ad
130 dd038bc6 2021-09-21 thomas.ad int32_t uuid_equal(struct uuid *, struct uuid *, uint32_t *);
131 dd038bc6 2021-09-21 thomas.ad int32_t uuid_is_nil(struct uuid *, uint32_t *);
132 dd038bc6 2021-09-21 thomas.ad void uuid_create(uuid_t *, uint32_t *);
133 dd038bc6 2021-09-21 thomas.ad void uuid_create_nil(struct uuid *, uint32_t *);
134 dd038bc6 2021-09-21 thomas.ad void uuid_from_string(const char *, uuid_t *, uint32_t *);
135 dd038bc6 2021-09-21 thomas.ad void uuid_to_string(uuid_t *, char **, uint32_t *);
136 9d70a0bf 2022-02-26 thomas #else
137 9d70a0bf 2022-02-26 thomas #include <uuid.h>
138 dd038bc6 2021-09-21 thomas.ad #endif
139 dd038bc6 2021-09-21 thomas.ad
140 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_STDINT_H
141 dd038bc6 2021-09-21 thomas.ad #include <stdint.h>
142 dd038bc6 2021-09-21 thomas.ad #else
143 dd038bc6 2021-09-21 thomas.ad #include <inttypes.h>
144 dd038bc6 2021-09-21 thomas.ad #endif
145 dd038bc6 2021-09-21 thomas.ad
146 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_QUEUE_H
147 dd038bc6 2021-09-21 thomas.ad #include <sys/queue.h>
148 dd038bc6 2021-09-21 thomas.ad #else
149 dd038bc6 2021-09-21 thomas.ad #include "compat/queue.h"
150 dd038bc6 2021-09-21 thomas.ad #endif
151 dd038bc6 2021-09-21 thomas.ad
152 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_TREE_H
153 dd038bc6 2021-09-21 thomas.ad #include <sys/tree.h>
154 dd038bc6 2021-09-21 thomas.ad #else
155 dd038bc6 2021-09-21 thomas.ad #include "compat/tree.h"
156 dd038bc6 2021-09-21 thomas.ad #endif
157 dd038bc6 2021-09-21 thomas.ad
158 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_UTIL_H
159 dd038bc6 2021-09-21 thomas.ad #include <util.h>
160 dd038bc6 2021-09-21 thomas.ad #endif
161 dd038bc6 2021-09-21 thomas.ad
162 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_LIBUTIL_H
163 dd038bc6 2021-09-21 thomas.ad #include <libutil.h>
164 dd038bc6 2021-09-21 thomas.ad #endif
165 dd038bc6 2021-09-21 thomas.ad
166 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_IMSG
167 dd038bc6 2021-09-21 thomas.ad #else
168 dd038bc6 2021-09-21 thomas.ad #include "compat/imsg.h"
169 ddd12270 2022-04-22 thomas #endif
170 ddd12270 2022-04-22 thomas
171 ddd12270 2022-04-22 thomas #ifdef HAVE_SIPHASH
172 ddd12270 2022-04-22 thomas #include <siphash.h>
173 ddd12270 2022-04-22 thomas #else
174 ddd12270 2022-04-22 thomas #include "compat/siphash.h"
175 dd038bc6 2021-09-21 thomas.ad #endif
176 dd038bc6 2021-09-21 thomas.ad
177 81e077a6 2022-03-08 thomas /* Include Apple-specific headers. Mostly for crypto.*/
178 81e077a6 2022-03-08 thomas #if defined(__APPLE__)
179 d24ddaa6 2022-02-26 thomas #define COMMON_DIGEST_FOR_OPENSSL
180 d24ddaa6 2022-02-26 thomas #include <CommonCrypto/CommonDigest.h>
181 d24ddaa6 2022-02-26 thomas #endif
182 d24ddaa6 2022-02-26 thomas
183 b26177ad 2022-03-03 thomas #if defined(HAVE_LIBCRYPTO) && !defined(__APPLE__) && !defined(__DragonFly__)
184 92a9e85d 2021-09-24 thomas #include <sha1.h>
185 b26177ad 2022-03-03 thomas #elif !defined(__APPLE__) && !defined(__DragonFly__)
186 92a9e85d 2021-09-24 thomas #include <sha.h>
187 b26177ad 2022-03-03 thomas #elif defined(__DragonFly__)
188 b26177ad 2022-03-03 thomas #include <openssl/sha.h>
189 d24ddaa6 2022-02-26 thomas #endif
190 92a9e85d 2021-09-24 thomas
191 b26177ad 2022-03-03 thomas #if !defined(HAVE_LIBCRYPTO) || defined(__APPLE__) || defined(__DragonFly__)
192 92a9e85d 2021-09-24 thomas #define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
193 92a9e85d 2021-09-24 thomas #define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
194 92a9e85d 2021-09-24 thomas
195 92a9e85d 2021-09-24 thomas #define SHA1_CTX SHA_CTX
196 92a9e85d 2021-09-24 thomas #define SHA1Init SHA1_Init
197 92a9e85d 2021-09-24 thomas #define SHA1Update SHA1_Update
198 92a9e85d 2021-09-24 thomas #define SHA1Final SHA1_Final
199 92a9e85d 2021-09-24 thomas #endif
200 92a9e85d 2021-09-24 thomas
201 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_ASPRINTF
202 dd038bc6 2021-09-21 thomas.ad /* asprintf.c */
203 dd038bc6 2021-09-21 thomas.ad int asprintf(char **, const char *, ...);
204 dd038bc6 2021-09-21 thomas.ad int vasprintf(char **, const char *, va_list);
205 dd038bc6 2021-09-21 thomas.ad #endif
206 dd038bc6 2021-09-21 thomas.ad
207 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_EXPLICIT_BZERO
208 dd038bc6 2021-09-21 thomas.ad /* explicit_bzero.c */
209 dd038bc6 2021-09-21 thomas.ad void explicit_bzero(void *, size_t);
210 dd038bc6 2021-09-21 thomas.ad #endif
211 dd038bc6 2021-09-21 thomas.ad
212 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_GETDTABLECOUNT
213 dd038bc6 2021-09-21 thomas.ad /* getdtablecount.c */
214 dd038bc6 2021-09-21 thomas.ad int getdtablecount(void);
215 dd038bc6 2021-09-21 thomas.ad #endif
216 dd038bc6 2021-09-21 thomas.ad
217 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_CLOSEFROM
218 dd038bc6 2021-09-21 thomas.ad /* closefrom.c */
219 d24ddaa6 2022-02-26 thomas void closefrom(int);
220 dd038bc6 2021-09-21 thomas.ad #endif
221 dd038bc6 2021-09-21 thomas.ad
222 92a9e85d 2021-09-24 thomas #if defined (__FreeBSD__)
223 92a9e85d 2021-09-24 thomas #define closefrom(fd) (closefrom(fd), 0)
224 92a9e85d 2021-09-24 thomas #endif
225 92a9e85d 2021-09-24 thomas
226 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRSEP
227 dd038bc6 2021-09-21 thomas.ad /* strsep.c */
228 dd038bc6 2021-09-21 thomas.ad char *strsep(char **, const char *);
229 dd038bc6 2021-09-21 thomas.ad #endif
230 dd038bc6 2021-09-21 thomas.ad
231 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRTONUM
232 dd038bc6 2021-09-21 thomas.ad /* strtonum.c */
233 dd038bc6 2021-09-21 thomas.ad long long strtonum(const char *, long long, long long, const char **);
234 dd038bc6 2021-09-21 thomas.ad #endif
235 dd038bc6 2021-09-21 thomas.ad
236 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRLCPY
237 dd038bc6 2021-09-21 thomas.ad /* strlcpy.c */
238 dd038bc6 2021-09-21 thomas.ad size_t strlcpy(char *, const char *, size_t);
239 dd038bc6 2021-09-21 thomas.ad #endif
240 dd038bc6 2021-09-21 thomas.ad
241 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRLCAT
242 dd038bc6 2021-09-21 thomas.ad /* strlcat.c */
243 dd038bc6 2021-09-21 thomas.ad size_t strlcat(char *, const char *, size_t);
244 dd038bc6 2021-09-21 thomas.ad #endif
245 dd038bc6 2021-09-21 thomas.ad
246 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRNLEN
247 dd038bc6 2021-09-21 thomas.ad /* strnlen.c */
248 dd038bc6 2021-09-21 thomas.ad size_t strnlen(const char *, size_t);
249 dd038bc6 2021-09-21 thomas.ad #endif
250 dd038bc6 2021-09-21 thomas.ad
251 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRNDUP
252 dd038bc6 2021-09-21 thomas.ad /* strndup.c */
253 dd038bc6 2021-09-21 thomas.ad char *strndup(const char *, size_t);
254 dd038bc6 2021-09-21 thomas.ad #endif
255 dd038bc6 2021-09-21 thomas.ad
256 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_GETPROGNAME
257 dd038bc6 2021-09-21 thomas.ad /* getprogname.c */
258 dd038bc6 2021-09-21 thomas.ad const char *getprogname(void);
259 dd038bc6 2021-09-21 thomas.ad #endif
260 dd038bc6 2021-09-21 thomas.ad
261 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_GETLINE
262 dd038bc6 2021-09-21 thomas.ad /* getline.c */
263 dd038bc6 2021-09-21 thomas.ad ssize_t getline(char **, size_t *, FILE *);
264 dd038bc6 2021-09-21 thomas.ad #endif
265 dd038bc6 2021-09-21 thomas.ad
266 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_FREEZERO
267 dd038bc6 2021-09-21 thomas.ad /* freezero.c */
268 dd038bc6 2021-09-21 thomas.ad void freezero(void *, size_t);
269 dd038bc6 2021-09-21 thomas.ad #endif
270 dd038bc6 2021-09-21 thomas.ad
271 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_GETDTABLECOUNT
272 dd038bc6 2021-09-21 thomas.ad /* getdtablecount.c */
273 dd038bc6 2021-09-21 thomas.ad int getdtablecount(void);
274 dd038bc6 2021-09-21 thomas.ad #endif
275 dd038bc6 2021-09-21 thomas.ad
276 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_REALLOCARRAY
277 dd038bc6 2021-09-21 thomas.ad /* reallocarray.c */
278 dd038bc6 2021-09-21 thomas.ad void *reallocarray(void *, size_t, size_t);
279 dd038bc6 2021-09-21 thomas.ad #endif
280 dd038bc6 2021-09-21 thomas.ad
281 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_RECALLOCARRAY
282 dd038bc6 2021-09-21 thomas.ad /* recallocarray.c */
283 dd038bc6 2021-09-21 thomas.ad void *recallocarray(void *, size_t, size_t, size_t);
284 dd038bc6 2021-09-21 thomas.ad #endif
285 dd038bc6 2021-09-21 thomas.ad
286 685f4593 2022-07-15 thomas #ifndef HAVE_SETPROCTITLE
287 685f4593 2022-07-15 thomas /* setproctitle.c */
288 685f4593 2022-07-15 thomas void setproctitle(const char *, ...);
289 685f4593 2022-07-15 thomas #endif
290 685f4593 2022-07-15 thomas
291 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_FMT_SCALED
292 dd038bc6 2021-09-21 thomas.ad /* fmt_scaled.c */
293 dd038bc6 2021-09-21 thomas.ad int fmt_scaled(long long, char *);
294 dd038bc6 2021-09-21 thomas.ad int scan_scaled(char *, long long *);
295 dd038bc6 2021-09-21 thomas.ad #define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
296 dd038bc6 2021-09-21 thomas.ad #endif
297 dd038bc6 2021-09-21 thomas.ad
298 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_LIBBSD
299 dd038bc6 2021-09-21 thomas.ad /* getopt.c */
300 dd038bc6 2021-09-21 thomas.ad extern int BSDopterr;
301 dd038bc6 2021-09-21 thomas.ad extern int BSDoptind;
302 dd038bc6 2021-09-21 thomas.ad extern int BSDoptopt;
303 dd038bc6 2021-09-21 thomas.ad extern int BSDoptreset;
304 dd038bc6 2021-09-21 thomas.ad extern char *BSDoptarg;
305 dd038bc6 2021-09-21 thomas.ad int BSDgetopt(int, char *const *, const char *);
306 dd038bc6 2021-09-21 thomas.ad #define getopt(ac, av, o) BSDgetopt(ac, av, o)
307 dd038bc6 2021-09-21 thomas.ad #define opterr BSDopterr
308 dd038bc6 2021-09-21 thomas.ad #define optind BSDoptind
309 dd038bc6 2021-09-21 thomas.ad #define optopt BSDoptopt
310 dd038bc6 2021-09-21 thomas.ad #define optreset BSDoptreset
311 dd038bc6 2021-09-21 thomas.ad #define optarg BSDoptarg
312 dd038bc6 2021-09-21 thomas.ad #endif
313 dd038bc6 2021-09-21 thomas.ad #endif
314 dd038bc6 2021-09-21 thomas.ad
315 de1dbfe9 2022-01-05 thomas /* Check for some of the non-portable timespec*() functions.
316 de1dbfe9 2022-01-05 thomas * This should largely come from libbsd for systems which
317 de1dbfe9 2022-01-05 thomas * aren't BSD, but this will depend on how old the library
318 de1dbfe9 2022-01-05 thomas * is.
319 de1dbfe9 2022-01-05 thomas */
320 de1dbfe9 2022-01-05 thomas #ifndef timespecisset
321 de1dbfe9 2022-01-05 thomas #define timespecisset(tsp) \
322 de1dbfe9 2022-01-05 thomas ((tsp)->tv_sec || (tsp)->tv_nsec)
323 de1dbfe9 2022-01-05 thomas #endif
324 de1dbfe9 2022-01-05 thomas
325 de1dbfe9 2022-01-05 thomas #ifndef timespecsub
326 de1dbfe9 2022-01-05 thomas #define timespecsub(tsp, usp, vsp) \
327 de1dbfe9 2022-01-05 thomas do { \
328 de1dbfe9 2022-01-05 thomas (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
329 de1dbfe9 2022-01-05 thomas (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
330 de1dbfe9 2022-01-05 thomas if ((vsp)->tv_nsec < 0) { \
331 de1dbfe9 2022-01-05 thomas (vsp)->tv_sec--; \
332 de1dbfe9 2022-01-05 thomas (vsp)->tv_nsec += 1000000000L; \
333 de1dbfe9 2022-01-05 thomas } \
334 de1dbfe9 2022-01-05 thomas } while (0)
335 de1dbfe9 2022-01-05 thomas #endif
336 de1dbfe9 2022-01-05 thomas
337 de1dbfe9 2022-01-05 thomas #ifndef timespeccmp
338 de1dbfe9 2022-01-05 thomas #define timespeccmp(tvp, uvp, cmp) \
339 de1dbfe9 2022-01-05 thomas (((tvp)->tv_sec == (uvp)->tv_sec) ? \
340 de1dbfe9 2022-01-05 thomas ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \
341 de1dbfe9 2022-01-05 thomas ((tvp)->tv_sec cmp (uvp)->tv_sec))
342 de1dbfe9 2022-01-05 thomas #endif
343 de1dbfe9 2022-01-05 thomas
344 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_BSD_MERGESORT
345 dd038bc6 2021-09-21 thomas.ad /* mergesort.c */
346 dd038bc6 2021-09-21 thomas.ad int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
347 dd038bc6 2021-09-21 thomas.ad #endif