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 6aa6ad44 2022-07-16 thomas #include <grp.h>
39 92a9e85d 2021-09-24 thomas #endif
40 dd038bc6 2021-09-21 thomas.ad
41 dd038bc6 2021-09-21 thomas.ad #include <fnmatch.h>
42 dd038bc6 2021-09-21 thomas.ad #include <limits.h>
43 dd038bc6 2021-09-21 thomas.ad #include <stdio.h>
44 dd038bc6 2021-09-21 thomas.ad #include <stdint.h>
45 dd038bc6 2021-09-21 thomas.ad
46 dd038bc6 2021-09-21 thomas.ad /* For flock. */
47 dd038bc6 2021-09-21 thomas.ad #ifndef O_EXLOCK
48 dd038bc6 2021-09-21 thomas.ad #define O_EXLOCK 0
49 dd038bc6 2021-09-21 thomas.ad #endif
50 dd038bc6 2021-09-21 thomas.ad
51 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_FLOCK
52 dd038bc6 2021-09-21 thomas.ad #define LOCK_SH 0
53 dd038bc6 2021-09-21 thomas.ad #define LOCK_EX 0
54 dd038bc6 2021-09-21 thomas.ad #define LOCK_NB 0
55 dd038bc6 2021-09-21 thomas.ad #define flock(fd, op) (0)
56 dd038bc6 2021-09-21 thomas.ad #else
57 dd038bc6 2021-09-21 thomas.ad #include <sys/file.h>
58 dd038bc6 2021-09-21 thomas.ad #endif
59 dd038bc6 2021-09-21 thomas.ad
60 21bb1653 2022-07-16 thomas /* POSIX doesn't define WAIT_ANY, so provide it if it's not found. */
61 21bb1653 2022-07-16 thomas #ifndef WAIT_ANY
62 21bb1653 2022-07-16 thomas #define WAIT_ANY (-1)
63 21bb1653 2022-07-16 thomas #endif
64 21bb1653 2022-07-16 thomas
65 ba107e80 2022-07-16 thomas /* SOCK_NONBLOCK isn't available across BSDs... */
66 ba107e80 2022-07-16 thomas #ifndef SOCK_NONBLOCK
67 ba107e80 2022-07-16 thomas #define SOCK_NONBLOCK 00004000
68 ba107e80 2022-07-16 thomas #endif
69 ba107e80 2022-07-16 thomas
70 2fcd7106 2022-07-16 thomas /* On FreeBSD (and possibly others), EAI_NODATA was removed, in favour of
71 2fcd7106 2022-07-16 thomas * using EAI_NONAME.
72 2fcd7106 2022-07-16 thomas */
73 2fcd7106 2022-07-16 thomas #ifndef EAI_NODATA
74 2fcd7106 2022-07-16 thomas #define EAI_NODATA EAI_NONAME
75 2fcd7106 2022-07-16 thomas #endif
76 2fcd7106 2022-07-16 thomas
77 dd038bc6 2021-09-21 thomas.ad #ifndef __dead
78 dd038bc6 2021-09-21 thomas.ad #define __dead __attribute__ ((__noreturn__))
79 c4e2e0d0 2022-07-16 thomas #endif
80 c4e2e0d0 2022-07-16 thomas
81 c4e2e0d0 2022-07-16 thomas #ifndef __unused
82 c4e2e0d0 2022-07-16 thomas #define __unused __attribute__ ((__unused__))
83 dd038bc6 2021-09-21 thomas.ad #endif
84 dd038bc6 2021-09-21 thomas.ad
85 dd038bc6 2021-09-21 thomas.ad #ifndef __OpenBSD__
86 dd038bc6 2021-09-21 thomas.ad #define pledge(s, p) (0)
87 dd038bc6 2021-09-21 thomas.ad #define unveil(s, p) (0)
88 5d120ea8 2022-06-23 op #endif
89 5d120ea8 2022-06-23 op
90 ef0b17aa 2022-06-24 thomas #ifndef __FreeBSD__
91 5d120ea8 2022-06-23 op #define cap_enter() (0)
92 683ec58e 2022-07-16 thomas #endif
93 683ec58e 2022-07-16 thomas
94 683ec58e 2022-07-16 thomas #ifndef HAVE_SETRESGID
95 683ec58e 2022-07-16 thomas #define setresgid(a, b, c) (0)
96 683ec58e 2022-07-16 thomas #endif
97 683ec58e 2022-07-16 thomas
98 683ec58e 2022-07-16 thomas #ifndef HAVE_SETRESUID
99 683ec58e 2022-07-16 thomas #define setresuid(a, b, c) (0)
100 97799ccd 2022-02-06 thomas #endif
101 97799ccd 2022-02-06 thomas
102 97799ccd 2022-02-06 thomas #ifndef HAVE_LINUX_LANDLOCK_H
103 97799ccd 2022-02-06 thomas #define landlock_no_fs() (0)
104 97799ccd 2022-02-06 thomas #else
105 97799ccd 2022-02-06 thomas int landlock_no_fs(void);
106 dd038bc6 2021-09-21 thomas.ad #endif
107 dd038bc6 2021-09-21 thomas.ad
108 dd038bc6 2021-09-21 thomas.ad #ifndef INFTIM
109 dd038bc6 2021-09-21 thomas.ad #define INFTIM -1
110 dd038bc6 2021-09-21 thomas.ad #endif
111 dd038bc6 2021-09-21 thomas.ad
112 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_BSD_UUID
113 dd038bc6 2021-09-21 thomas.ad #include <uuid/uuid.h>
114 dd038bc6 2021-09-21 thomas.ad #define uuid_s_ok 0
115 dd038bc6 2021-09-21 thomas.ad #define uuid_s_bad_version 1
116 dd038bc6 2021-09-21 thomas.ad #define uuid_s_invalid_string_uuid 2
117 dd038bc6 2021-09-21 thomas.ad #define uuid_s_no_memory 3
118 dd038bc6 2021-09-21 thomas.ad
119 dd038bc6 2021-09-21 thomas.ad /* Length of a node address (an IEEE 802 address). */
120 dd038bc6 2021-09-21 thomas.ad #define _UUID_NODE_LEN 6
121 dd038bc6 2021-09-21 thomas.ad
122 dd038bc6 2021-09-21 thomas.ad struct uuid {
123 dd038bc6 2021-09-21 thomas.ad uint32_t time_low;
124 dd038bc6 2021-09-21 thomas.ad uint16_t time_mid;
125 dd038bc6 2021-09-21 thomas.ad uint16_t time_hi_and_version;
126 dd038bc6 2021-09-21 thomas.ad uint8_t clock_seq_hi_and_reserved;
127 dd038bc6 2021-09-21 thomas.ad uint8_t clock_seq_low;
128 dd038bc6 2021-09-21 thomas.ad uint8_t node[_UUID_NODE_LEN];
129 dd038bc6 2021-09-21 thomas.ad };
130 dd038bc6 2021-09-21 thomas.ad
131 dd038bc6 2021-09-21 thomas.ad int32_t uuid_equal(struct uuid *, struct uuid *, uint32_t *);
132 dd038bc6 2021-09-21 thomas.ad int32_t uuid_is_nil(struct uuid *, uint32_t *);
133 dd038bc6 2021-09-21 thomas.ad void uuid_create(uuid_t *, uint32_t *);
134 dd038bc6 2021-09-21 thomas.ad void uuid_create_nil(struct uuid *, uint32_t *);
135 dd038bc6 2021-09-21 thomas.ad void uuid_from_string(const char *, uuid_t *, uint32_t *);
136 dd038bc6 2021-09-21 thomas.ad void uuid_to_string(uuid_t *, char **, uint32_t *);
137 9d70a0bf 2022-02-26 thomas #else
138 9d70a0bf 2022-02-26 thomas #include <uuid.h>
139 dd038bc6 2021-09-21 thomas.ad #endif
140 dd038bc6 2021-09-21 thomas.ad
141 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_STDINT_H
142 dd038bc6 2021-09-21 thomas.ad #include <stdint.h>
143 dd038bc6 2021-09-21 thomas.ad #else
144 dd038bc6 2021-09-21 thomas.ad #include <inttypes.h>
145 dd038bc6 2021-09-21 thomas.ad #endif
146 dd038bc6 2021-09-21 thomas.ad
147 46384c6e 2022-09-13 thomas #ifdef HAVE_QUEUE_H
148 19467d59 2022-07-16 thomas #include <sys/queue.h>
149 dd038bc6 2021-09-21 thomas.ad #endif
150 dd038bc6 2021-09-21 thomas.ad
151 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_TREE_H
152 dd038bc6 2021-09-21 thomas.ad #include <sys/tree.h>
153 dd038bc6 2021-09-21 thomas.ad #else
154 dd038bc6 2021-09-21 thomas.ad #include "compat/tree.h"
155 dd038bc6 2021-09-21 thomas.ad #endif
156 dd038bc6 2021-09-21 thomas.ad
157 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_UTIL_H
158 dd038bc6 2021-09-21 thomas.ad #include <util.h>
159 dd038bc6 2021-09-21 thomas.ad #endif
160 dd038bc6 2021-09-21 thomas.ad
161 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_LIBUTIL_H
162 dd038bc6 2021-09-21 thomas.ad #include <libutil.h>
163 dd038bc6 2021-09-21 thomas.ad #endif
164 dd038bc6 2021-09-21 thomas.ad
165 dd038bc6 2021-09-21 thomas.ad #ifdef HAVE_IMSG
166 dd038bc6 2021-09-21 thomas.ad #else
167 dd038bc6 2021-09-21 thomas.ad #include "compat/imsg.h"
168 ddd12270 2022-04-22 thomas #endif
169 ddd12270 2022-04-22 thomas
170 ddd12270 2022-04-22 thomas #ifdef HAVE_SIPHASH
171 ddd12270 2022-04-22 thomas #include <siphash.h>
172 ddd12270 2022-04-22 thomas #else
173 ddd12270 2022-04-22 thomas #include "compat/siphash.h"
174 dd038bc6 2021-09-21 thomas.ad #endif
175 dd038bc6 2021-09-21 thomas.ad
176 81e077a6 2022-03-08 thomas /* Include Apple-specific headers. Mostly for crypto.*/
177 81e077a6 2022-03-08 thomas #if defined(__APPLE__)
178 d24ddaa6 2022-02-26 thomas #define COMMON_DIGEST_FOR_OPENSSL
179 d24ddaa6 2022-02-26 thomas #include <CommonCrypto/CommonDigest.h>
180 d24ddaa6 2022-02-26 thomas #endif
181 d24ddaa6 2022-02-26 thomas
182 98670ba7 2023-02-23 thomas #ifdef HAVE_SHA_AS_SHA1
183 98670ba7 2023-02-23 thomas # include <sha.h>
184 98670ba7 2023-02-23 thomas #endif
185 98670ba7 2023-02-23 thomas #ifdef HAVE_SHA1_AS_SHA1
186 98670ba7 2023-02-23 thomas # include <sha1.h>
187 98670ba7 2023-02-23 thomas #endif
188 98670ba7 2023-02-23 thomas #ifdef HAVE_SHA2
189 98670ba7 2023-02-23 thomas # include <sha2.h>
190 98670ba7 2023-02-23 thomas #endif
191 98670ba7 2023-02-23 thomas #ifdef HAVE_SHA256
192 98670ba7 2023-02-23 thomas # include <sha256.h>
193 98670ba7 2023-02-23 thomas #endif
194 98670ba7 2023-02-23 thomas
195 98670ba7 2023-02-23 thomas /* Catch-all for systems where the header files don't exist and/or the below
196 98670ba7 2023-02-23 thomas * still are not defined.
197 98670ba7 2023-02-23 thomas */
198 98670ba7 2023-02-23 thomas #ifndef SHA256_DIGEST_LENGTH
199 98670ba7 2023-02-23 thomas #define SHA256_DIGEST_LENGTH 32
200 98670ba7 2023-02-23 thomas #endif
201 98670ba7 2023-02-23 thomas
202 98670ba7 2023-02-23 thomas #ifndef SHA256_DIGEST_STRING_LENGTH
203 98670ba7 2023-02-23 thomas #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
204 98670ba7 2023-02-23 thomas #endif
205 98670ba7 2023-02-23 thomas
206 98670ba7 2023-02-23 thomas #if defined(__DragonFly__)
207 b26177ad 2022-03-03 thomas #include <openssl/sha.h>
208 d24ddaa6 2022-02-26 thomas #endif
209 92a9e85d 2021-09-24 thomas
210 98670ba7 2023-02-23 thomas #ifdef NEEDS_SHA1_DEFS
211 92a9e85d 2021-09-24 thomas #define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
212 92a9e85d 2021-09-24 thomas #define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
213 92a9e85d 2021-09-24 thomas
214 92a9e85d 2021-09-24 thomas #define SHA1_CTX SHA_CTX
215 92a9e85d 2021-09-24 thomas #define SHA1Init SHA1_Init
216 92a9e85d 2021-09-24 thomas #define SHA1Update SHA1_Update
217 92a9e85d 2021-09-24 thomas #define SHA1Final SHA1_Final
218 75716fd6 2022-08-27 thomas #endif
219 75716fd6 2022-08-27 thomas
220 75716fd6 2022-08-27 thomas /*
221 75716fd6 2022-08-27 thomas * The following SA_LEN/SS_LEN dance comes from various source, notably
222 75716fd6 2022-08-27 thomas * OpenSMTP by way of OpenNTPD and OpenBGPD (thanks everyone!). got-portable
223 75716fd6 2022-08-27 thomas * has tweaked a lot of the following macros to suit the needs of
224 75716fd6 2022-08-27 thomas * got-portable.
225 75716fd6 2022-08-27 thomas */
226 75716fd6 2022-08-27 thomas
227 75716fd6 2022-08-27 thomas /* From OpenNTPD portable */
228 75716fd6 2022-08-27 thomas #if !defined(SA_LEN)
229 75716fd6 2022-08-27 thomas # if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
230 75716fd6 2022-08-27 thomas # define SA_LEN(x) ((x)->sa_len)
231 75716fd6 2022-08-27 thomas # else
232 75716fd6 2022-08-27 thomas # define SA_LEN(x) ((x)->sa_family == AF_INET6 ? \
233 75716fd6 2022-08-27 thomas sizeof(struct sockaddr_in6) : \
234 75716fd6 2022-08-27 thomas sizeof(struct sockaddr_in))
235 75716fd6 2022-08-27 thomas # endif
236 75716fd6 2022-08-27 thomas
237 92a9e85d 2021-09-24 thomas #endif
238 92a9e85d 2021-09-24 thomas
239 75716fd6 2022-08-27 thomas /* From OpenBGPD portable */
240 75716fd6 2022-08-27 thomas #if !defined(SS_LEN)
241 75716fd6 2022-08-27 thomas # if defined(HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN)
242 75716fd6 2022-08-27 thomas # define SS_LEN(x) ((x)->ss_len)
243 75716fd6 2022-08-27 thomas # else
244 75716fd6 2022-08-27 thomas # define SS_LEN(x) SA_LEN((struct sockaddr *)(x))
245 75716fd6 2022-08-27 thomas # endif
246 75716fd6 2022-08-27 thomas #endif
247 75716fd6 2022-08-27 thomas
248 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_ASPRINTF
249 dd038bc6 2021-09-21 thomas.ad /* asprintf.c */
250 dd038bc6 2021-09-21 thomas.ad int asprintf(char **, const char *, ...);
251 dd038bc6 2021-09-21 thomas.ad int vasprintf(char **, const char *, va_list);
252 dd038bc6 2021-09-21 thomas.ad #endif
253 dd038bc6 2021-09-21 thomas.ad
254 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_EXPLICIT_BZERO
255 dd038bc6 2021-09-21 thomas.ad /* explicit_bzero.c */
256 dd038bc6 2021-09-21 thomas.ad void explicit_bzero(void *, size_t);
257 dd038bc6 2021-09-21 thomas.ad #endif
258 dd038bc6 2021-09-21 thomas.ad
259 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_GETDTABLECOUNT
260 dd038bc6 2021-09-21 thomas.ad /* getdtablecount.c */
261 dd038bc6 2021-09-21 thomas.ad int getdtablecount(void);
262 dd038bc6 2021-09-21 thomas.ad #endif
263 dd038bc6 2021-09-21 thomas.ad
264 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_CLOSEFROM
265 dd038bc6 2021-09-21 thomas.ad /* closefrom.c */
266 d24ddaa6 2022-02-26 thomas void closefrom(int);
267 dd038bc6 2021-09-21 thomas.ad #endif
268 dd038bc6 2021-09-21 thomas.ad
269 92a9e85d 2021-09-24 thomas #if defined (__FreeBSD__)
270 92a9e85d 2021-09-24 thomas #define closefrom(fd) (closefrom(fd), 0)
271 92a9e85d 2021-09-24 thomas #endif
272 92a9e85d 2021-09-24 thomas
273 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRSEP
274 dd038bc6 2021-09-21 thomas.ad /* strsep.c */
275 dd038bc6 2021-09-21 thomas.ad char *strsep(char **, const char *);
276 dd038bc6 2021-09-21 thomas.ad #endif
277 dd038bc6 2021-09-21 thomas.ad
278 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRTONUM
279 dd038bc6 2021-09-21 thomas.ad /* strtonum.c */
280 dd038bc6 2021-09-21 thomas.ad long long strtonum(const char *, long long, long long, const char **);
281 dd038bc6 2021-09-21 thomas.ad #endif
282 dd038bc6 2021-09-21 thomas.ad
283 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRLCPY
284 dd038bc6 2021-09-21 thomas.ad /* strlcpy.c */
285 dd038bc6 2021-09-21 thomas.ad size_t strlcpy(char *, const char *, size_t);
286 dd038bc6 2021-09-21 thomas.ad #endif
287 dd038bc6 2021-09-21 thomas.ad
288 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRLCAT
289 dd038bc6 2021-09-21 thomas.ad /* strlcat.c */
290 dd038bc6 2021-09-21 thomas.ad size_t strlcat(char *, const char *, size_t);
291 dd038bc6 2021-09-21 thomas.ad #endif
292 dd038bc6 2021-09-21 thomas.ad
293 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRNLEN
294 dd038bc6 2021-09-21 thomas.ad /* strnlen.c */
295 dd038bc6 2021-09-21 thomas.ad size_t strnlen(const char *, size_t);
296 dd038bc6 2021-09-21 thomas.ad #endif
297 dd038bc6 2021-09-21 thomas.ad
298 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_STRNDUP
299 dd038bc6 2021-09-21 thomas.ad /* strndup.c */
300 dd038bc6 2021-09-21 thomas.ad char *strndup(const char *, size_t);
301 dd038bc6 2021-09-21 thomas.ad #endif
302 dd038bc6 2021-09-21 thomas.ad
303 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_GETPROGNAME
304 dd038bc6 2021-09-21 thomas.ad /* getprogname.c */
305 dd038bc6 2021-09-21 thomas.ad const char *getprogname(void);
306 dd038bc6 2021-09-21 thomas.ad #endif
307 dd038bc6 2021-09-21 thomas.ad
308 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_GETLINE
309 dd038bc6 2021-09-21 thomas.ad /* getline.c */
310 dd038bc6 2021-09-21 thomas.ad ssize_t getline(char **, size_t *, FILE *);
311 dd038bc6 2021-09-21 thomas.ad #endif
312 dd038bc6 2021-09-21 thomas.ad
313 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_FREEZERO
314 dd038bc6 2021-09-21 thomas.ad /* freezero.c */
315 dd038bc6 2021-09-21 thomas.ad void freezero(void *, size_t);
316 dd038bc6 2021-09-21 thomas.ad #endif
317 dd038bc6 2021-09-21 thomas.ad
318 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_GETDTABLECOUNT
319 dd038bc6 2021-09-21 thomas.ad /* getdtablecount.c */
320 dd038bc6 2021-09-21 thomas.ad int getdtablecount(void);
321 dd038bc6 2021-09-21 thomas.ad #endif
322 dd038bc6 2021-09-21 thomas.ad
323 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_REALLOCARRAY
324 dd038bc6 2021-09-21 thomas.ad /* reallocarray.c */
325 dd038bc6 2021-09-21 thomas.ad void *reallocarray(void *, size_t, size_t);
326 dd038bc6 2021-09-21 thomas.ad #endif
327 dd038bc6 2021-09-21 thomas.ad
328 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_RECALLOCARRAY
329 dd038bc6 2021-09-21 thomas.ad /* recallocarray.c */
330 dd038bc6 2021-09-21 thomas.ad void *recallocarray(void *, size_t, size_t, size_t);
331 dd038bc6 2021-09-21 thomas.ad #endif
332 dd038bc6 2021-09-21 thomas.ad
333 c4e2e0d0 2022-07-16 thomas #ifndef HAVE_SETPROCTITLE
334 c4e2e0d0 2022-07-16 thomas /* setproctitle.c */
335 c4e2e0d0 2022-07-16 thomas void setproctitle(const char *, ...);
336 c4e2e0d0 2022-07-16 thomas #endif
337 c4e2e0d0 2022-07-16 thomas
338 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_FMT_SCALED
339 dd038bc6 2021-09-21 thomas.ad /* fmt_scaled.c */
340 dd038bc6 2021-09-21 thomas.ad int fmt_scaled(long long, char *);
341 dd038bc6 2021-09-21 thomas.ad int scan_scaled(char *, long long *);
342 dd038bc6 2021-09-21 thomas.ad #define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
343 dd038bc6 2021-09-21 thomas.ad #endif
344 dd038bc6 2021-09-21 thomas.ad
345 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_LIBBSD
346 dd038bc6 2021-09-21 thomas.ad /* getopt.c */
347 dd038bc6 2021-09-21 thomas.ad extern int BSDopterr;
348 dd038bc6 2021-09-21 thomas.ad extern int BSDoptind;
349 dd038bc6 2021-09-21 thomas.ad extern int BSDoptopt;
350 dd038bc6 2021-09-21 thomas.ad extern int BSDoptreset;
351 dd038bc6 2021-09-21 thomas.ad extern char *BSDoptarg;
352 dd038bc6 2021-09-21 thomas.ad int BSDgetopt(int, char *const *, const char *);
353 dd038bc6 2021-09-21 thomas.ad #define getopt(ac, av, o) BSDgetopt(ac, av, o)
354 dd038bc6 2021-09-21 thomas.ad #define opterr BSDopterr
355 dd038bc6 2021-09-21 thomas.ad #define optind BSDoptind
356 dd038bc6 2021-09-21 thomas.ad #define optopt BSDoptopt
357 dd038bc6 2021-09-21 thomas.ad #define optreset BSDoptreset
358 dd038bc6 2021-09-21 thomas.ad #define optarg BSDoptarg
359 dd038bc6 2021-09-21 thomas.ad #endif
360 dd038bc6 2021-09-21 thomas.ad #endif
361 dd038bc6 2021-09-21 thomas.ad
362 de1dbfe9 2022-01-05 thomas /* Check for some of the non-portable timespec*() functions.
363 de1dbfe9 2022-01-05 thomas * This should largely come from libbsd for systems which
364 de1dbfe9 2022-01-05 thomas * aren't BSD, but this will depend on how old the library
365 de1dbfe9 2022-01-05 thomas * is.
366 de1dbfe9 2022-01-05 thomas */
367 de1dbfe9 2022-01-05 thomas #ifndef timespecisset
368 de1dbfe9 2022-01-05 thomas #define timespecisset(tsp) \
369 de1dbfe9 2022-01-05 thomas ((tsp)->tv_sec || (tsp)->tv_nsec)
370 de1dbfe9 2022-01-05 thomas #endif
371 de1dbfe9 2022-01-05 thomas
372 de1dbfe9 2022-01-05 thomas #ifndef timespecsub
373 de1dbfe9 2022-01-05 thomas #define timespecsub(tsp, usp, vsp) \
374 de1dbfe9 2022-01-05 thomas do { \
375 de1dbfe9 2022-01-05 thomas (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
376 de1dbfe9 2022-01-05 thomas (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
377 de1dbfe9 2022-01-05 thomas if ((vsp)->tv_nsec < 0) { \
378 de1dbfe9 2022-01-05 thomas (vsp)->tv_sec--; \
379 de1dbfe9 2022-01-05 thomas (vsp)->tv_nsec += 1000000000L; \
380 de1dbfe9 2022-01-05 thomas } \
381 de1dbfe9 2022-01-05 thomas } while (0)
382 de1dbfe9 2022-01-05 thomas #endif
383 de1dbfe9 2022-01-05 thomas
384 de1dbfe9 2022-01-05 thomas #ifndef timespeccmp
385 de1dbfe9 2022-01-05 thomas #define timespeccmp(tvp, uvp, cmp) \
386 de1dbfe9 2022-01-05 thomas (((tvp)->tv_sec == (uvp)->tv_sec) ? \
387 de1dbfe9 2022-01-05 thomas ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \
388 de1dbfe9 2022-01-05 thomas ((tvp)->tv_sec cmp (uvp)->tv_sec))
389 de1dbfe9 2022-01-05 thomas #endif
390 de1dbfe9 2022-01-05 thomas
391 dd038bc6 2021-09-21 thomas.ad #ifndef HAVE_BSD_MERGESORT
392 dd038bc6 2021-09-21 thomas.ad /* mergesort.c */
393 dd038bc6 2021-09-21 thomas.ad int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
394 dd038bc6 2021-09-21 thomas.ad #endif