Blame


1 47dc83f5 2023-03-08 thomas /*
2 47dc83f5 2023-03-08 thomas * Copyright (c) 2023 Thomas Adam <thomas@xteddy.org>
3 47dc83f5 2023-03-08 thomas *
4 47dc83f5 2023-03-08 thomas * Permission to use, copy, modify, and distribute this software for any
5 47dc83f5 2023-03-08 thomas * purpose with or without fee is hereby granted, provided that the above
6 47dc83f5 2023-03-08 thomas * copyright notice and this permission notice appear in all copies.
7 47dc83f5 2023-03-08 thomas *
8 47dc83f5 2023-03-08 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 47dc83f5 2023-03-08 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 47dc83f5 2023-03-08 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 47dc83f5 2023-03-08 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 47dc83f5 2023-03-08 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 47dc83f5 2023-03-08 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 47dc83f5 2023-03-08 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 47dc83f5 2023-03-08 thomas */
16 47dc83f5 2023-03-08 thomas
17 47dc83f5 2023-03-08 thomas #ifndef _GOT_COMPAT_H_2
18 47dc83f5 2023-03-08 thomas #define _GOT_COMPAT_H_2
19 4efc8dcb 2023-08-29 thomas
20 4efc8dcb 2023-08-29 thomas #ifdef HAVE_STDINT_H
21 4efc8dcb 2023-08-29 thomas #include <stdint.h>
22 4efc8dcb 2023-08-29 thomas #else
23 4efc8dcb 2023-08-29 thomas #include <inttypes.h>
24 4efc8dcb 2023-08-29 thomas #endif
25 47dc83f5 2023-03-08 thomas
26 7ef51333 2023-03-08 thomas #include <limits.h>
27 47dc83f5 2023-03-08 thomas #include <sys/uio.h>
28 7ef51333 2023-03-08 thomas
29 47dc83f5 2023-03-08 thomas #if defined(__FreeBSD__)
30 47dc83f5 2023-03-08 thomas #include <sys/endian.h>
31 47dc83f5 2023-03-08 thomas #include <sys/capsicum.h>
32 47dc83f5 2023-03-08 thomas #elif defined(__APPLE__)
33 47dc83f5 2023-03-08 thomas #include <machine/endian.h>
34 47dc83f5 2023-03-08 thomas #include <libkern/OSByteOrder.h>
35 47dc83f5 2023-03-08 thomas #include "compat/bsd-poll.h"
36 47dc83f5 2023-03-08 thomas
37 47dc83f5 2023-03-08 thomas #define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
38 47dc83f5 2023-03-08 thomas
39 47dc83f5 2023-03-08 thomas #define htobe16(x) OSSwapHostToBigInt16(x)
40 47dc83f5 2023-03-08 thomas #define htole16(x) OSSwapHostToLittleInt16(x)
41 47dc83f5 2023-03-08 thomas #define be16toh(x) OSSwapBigToHostInt16(x)
42 47dc83f5 2023-03-08 thomas #define le16toh(x) OSSwapLittleToHostInt16(x)
43 47dc83f5 2023-03-08 thomas
44 47dc83f5 2023-03-08 thomas #define htobe32(x) OSSwapHostToBigInt32(x)
45 47dc83f5 2023-03-08 thomas #define htole32(x) OSSwapHostToLittleInt32(x)
46 47dc83f5 2023-03-08 thomas #define be32toh(x) OSSwapBigToHostInt32(x)
47 47dc83f5 2023-03-08 thomas #define le32toh(x) OSSwapLittleToHostInt32(x)
48 47dc83f5 2023-03-08 thomas
49 47dc83f5 2023-03-08 thomas #define htobe64(x) OSSwapHostToBigInt64(x)
50 47dc83f5 2023-03-08 thomas #define htole64(x) OSSwapHostToLittleInt64(x)
51 47dc83f5 2023-03-08 thomas #define be64toh(x) OSSwapBigToHostInt64(x)
52 47dc83f5 2023-03-08 thomas #define le64toh(x) OSSwapLittleToHostInt64(x)
53 47dc83f5 2023-03-08 thomas
54 47dc83f5 2023-03-08 thomas #define st_atim st_atimespec
55 47dc83f5 2023-03-08 thomas #define st_ctim st_ctimespec
56 47dc83f5 2023-03-08 thomas #define st_mtim st_mtimespec
57 47dc83f5 2023-03-08 thomas
58 47dc83f5 2023-03-08 thomas #else /* Linux, etc... */
59 47dc83f5 2023-03-08 thomas #include <endian.h>
60 47dc83f5 2023-03-08 thomas #include <grp.h>
61 7ef51333 2023-03-08 thomas #include <stdlib.h>
62 47dc83f5 2023-03-08 thomas #endif
63 47dc83f5 2023-03-08 thomas
64 4fccd2fe 2023-03-08 thomas #ifndef __GNUC__
65 4fccd2fe 2023-03-08 thomas #define __attribute__(a)
66 4fccd2fe 2023-03-08 thomas #ifndef __bounded__
67 4fccd2fe 2023-03-08 thomas #define __bounded__(a, b, c)
68 8cff5e95 2023-03-08 thomas #endif
69 4fccd2fe 2023-03-08 thomas #endif
70 4fccd2fe 2023-03-08 thomas
71 8cff5e95 2023-03-08 thomas
72 e24c4959 2023-08-29 thomas #ifndef UID_MAX
73 e24c4959 2023-08-29 thomas # define UID_MAX UINT_MAX /* max value for a uid_t */
74 e24c4959 2023-08-29 thomas #endif
75 e24c4959 2023-08-29 thomas #ifndef GID_MAX
76 e24c4959 2023-08-29 thomas # define GID_MAX UINT_MAX /* max value for a gid_t */
77 e24c4959 2023-08-29 thomas #endif
78 e24c4959 2023-08-29 thomas
79 47dc83f5 2023-03-08 thomas /* For flock. */
80 47dc83f5 2023-03-08 thomas #ifndef O_EXLOCK
81 47dc83f5 2023-03-08 thomas #define O_EXLOCK 0
82 47dc83f5 2023-03-08 thomas #endif
83 47dc83f5 2023-03-08 thomas
84 47dc83f5 2023-03-08 thomas #ifndef HAVE_FLOCK
85 47dc83f5 2023-03-08 thomas #define LOCK_SH 0
86 47dc83f5 2023-03-08 thomas #define LOCK_EX 0
87 47dc83f5 2023-03-08 thomas #define LOCK_NB 0
88 47dc83f5 2023-03-08 thomas #define flock(fd, op) (0)
89 47dc83f5 2023-03-08 thomas #else
90 47dc83f5 2023-03-08 thomas #include <sys/file.h>
91 47dc83f5 2023-03-08 thomas #endif
92 47dc83f5 2023-03-08 thomas
93 47dc83f5 2023-03-08 thomas /* POSIX doesn't define WAIT_ANY, so provide it if it's not found. */
94 47dc83f5 2023-03-08 thomas #ifndef WAIT_ANY
95 47dc83f5 2023-03-08 thomas #define WAIT_ANY (-1)
96 47dc83f5 2023-03-08 thomas #endif
97 47dc83f5 2023-03-08 thomas
98 47dc83f5 2023-03-08 thomas /* On FreeBSD (and possibly others), EAI_NODATA was removed, in favour of
99 47dc83f5 2023-03-08 thomas * using EAI_NONAME.
100 47dc83f5 2023-03-08 thomas */
101 47dc83f5 2023-03-08 thomas #ifndef EAI_NODATA
102 47dc83f5 2023-03-08 thomas #define EAI_NODATA EAI_NONAME
103 47dc83f5 2023-03-08 thomas #endif
104 47dc83f5 2023-03-08 thomas
105 47dc83f5 2023-03-08 thomas #ifndef __dead
106 47dc83f5 2023-03-08 thomas #define __dead __attribute__ ((__noreturn__))
107 47dc83f5 2023-03-08 thomas #endif
108 47dc83f5 2023-03-08 thomas
109 47dc83f5 2023-03-08 thomas #ifndef __unused
110 47dc83f5 2023-03-08 thomas #define __unused __attribute__ ((__unused__))
111 47dc83f5 2023-03-08 thomas #endif
112 47dc83f5 2023-03-08 thomas
113 47dc83f5 2023-03-08 thomas #ifndef __OpenBSD__
114 47dc83f5 2023-03-08 thomas #define pledge(s, p) (0)
115 47dc83f5 2023-03-08 thomas #define unveil(s, p) (0)
116 47dc83f5 2023-03-08 thomas #endif
117 47dc83f5 2023-03-08 thomas
118 47dc83f5 2023-03-08 thomas #ifndef __FreeBSD__
119 47dc83f5 2023-03-08 thomas #define cap_enter() (0)
120 47dc83f5 2023-03-08 thomas #endif
121 47dc83f5 2023-03-08 thomas
122 206be139 2023-03-08 thomas #ifndef HAVE_B64_NTOP
123 206be139 2023-03-08 thomas #undef b64_ntop
124 206be139 2023-03-08 thomas #undef b64_pton
125 206be139 2023-03-08 thomas int b64_ntop(u_char const *, size_t, char *, size_t);
126 206be139 2023-03-08 thomas int b64_pton(char const *, u_char *, size_t);
127 206be139 2023-03-08 thomas #endif
128 206be139 2023-03-08 thomas
129 47dc83f5 2023-03-08 thomas #ifndef HAVE_SETRESGID
130 47dc83f5 2023-03-08 thomas #define setresgid(a, b, c) (0)
131 47dc83f5 2023-03-08 thomas #endif
132 47dc83f5 2023-03-08 thomas
133 47dc83f5 2023-03-08 thomas #ifndef HAVE_SETRESUID
134 47dc83f5 2023-03-08 thomas #define setresuid(a, b, c) (0)
135 47dc83f5 2023-03-08 thomas #endif
136 47dc83f5 2023-03-08 thomas
137 47dc83f5 2023-03-08 thomas #ifndef HAVE_LINUX_LANDLOCK_H
138 47dc83f5 2023-03-08 thomas #define landlock_no_fs() (0)
139 47dc83f5 2023-03-08 thomas #else
140 47dc83f5 2023-03-08 thomas int landlock_no_fs(void);
141 47dc83f5 2023-03-08 thomas #endif
142 47dc83f5 2023-03-08 thomas
143 47dc83f5 2023-03-08 thomas #ifndef INFTIM
144 47dc83f5 2023-03-08 thomas #define INFTIM -1
145 47dc83f5 2023-03-08 thomas #endif
146 47dc83f5 2023-03-08 thomas
147 47dc83f5 2023-03-08 thomas #ifndef HAVE_BSD_UUID
148 47dc83f5 2023-03-08 thomas #include <uuid/uuid.h>
149 47dc83f5 2023-03-08 thomas #define uuid_s_ok 0
150 47dc83f5 2023-03-08 thomas #define uuid_s_bad_version 1
151 47dc83f5 2023-03-08 thomas #define uuid_s_invalid_string_uuid 2
152 47dc83f5 2023-03-08 thomas #define uuid_s_no_memory 3
153 47dc83f5 2023-03-08 thomas
154 47dc83f5 2023-03-08 thomas /* Length of a node address (an IEEE 802 address). */
155 47dc83f5 2023-03-08 thomas #define _UUID_NODE_LEN 6
156 47dc83f5 2023-03-08 thomas
157 47dc83f5 2023-03-08 thomas struct uuid {
158 47dc83f5 2023-03-08 thomas uint32_t time_low;
159 47dc83f5 2023-03-08 thomas uint16_t time_mid;
160 47dc83f5 2023-03-08 thomas uint16_t time_hi_and_version;
161 47dc83f5 2023-03-08 thomas uint8_t clock_seq_hi_and_reserved;
162 47dc83f5 2023-03-08 thomas uint8_t clock_seq_low;
163 47dc83f5 2023-03-08 thomas uint8_t node[_UUID_NODE_LEN];
164 47dc83f5 2023-03-08 thomas };
165 47dc83f5 2023-03-08 thomas
166 47dc83f5 2023-03-08 thomas int32_t uuid_equal(struct uuid *, struct uuid *, uint32_t *);
167 47dc83f5 2023-03-08 thomas int32_t uuid_is_nil(struct uuid *, uint32_t *);
168 47dc83f5 2023-03-08 thomas void uuid_create(uuid_t *, uint32_t *);
169 47dc83f5 2023-03-08 thomas void uuid_create_nil(struct uuid *, uint32_t *);
170 47dc83f5 2023-03-08 thomas void uuid_from_string(const char *, uuid_t *, uint32_t *);
171 47dc83f5 2023-03-08 thomas void uuid_to_string(uuid_t *, char **, uint32_t *);
172 47dc83f5 2023-03-08 thomas #else
173 47dc83f5 2023-03-08 thomas #include <uuid.h>
174 47dc83f5 2023-03-08 thomas #endif
175 47dc83f5 2023-03-08 thomas
176 47dc83f5 2023-03-08 thomas #ifdef HAVE_QUEUE_H
177 47dc83f5 2023-03-08 thomas #include <sys/queue.h>
178 47dc83f5 2023-03-08 thomas #endif
179 47dc83f5 2023-03-08 thomas
180 4fccd2fe 2023-03-08 thomas #ifndef HAVE_TREE_H
181 47dc83f5 2023-03-08 thomas #include "compat/tree.h"
182 4fccd2fe 2023-03-08 thomas #else
183 4fccd2fe 2023-03-08 thomas #include <sys/tree.h>
184 47dc83f5 2023-03-08 thomas #endif
185 47dc83f5 2023-03-08 thomas
186 47dc83f5 2023-03-08 thomas #ifdef HAVE_UTIL_H
187 47dc83f5 2023-03-08 thomas #include <util.h>
188 47dc83f5 2023-03-08 thomas #endif
189 47dc83f5 2023-03-08 thomas
190 47dc83f5 2023-03-08 thomas #ifdef HAVE_LIBUTIL_H
191 47dc83f5 2023-03-08 thomas #include <libutil.h>
192 47dc83f5 2023-03-08 thomas #endif
193 47dc83f5 2023-03-08 thomas
194 4fccd2fe 2023-03-08 thomas #ifndef IOV_MAX
195 4fccd2fe 2023-03-08 thomas # define IOV_MAX 1024
196 4fccd2fe 2023-03-08 thomas #endif
197 4fccd2fe 2023-03-08 thomas
198 4fccd2fe 2023-03-08 thomas #ifndef HAVE_IMSG
199 47dc83f5 2023-03-08 thomas #include "compat/imsg.h"
200 8cff5e95 2023-03-08 thomas #else
201 8cff5e95 2023-03-08 thomas #include <imsg.h>
202 47dc83f5 2023-03-08 thomas #endif
203 47dc83f5 2023-03-08 thomas
204 4fccd2fe 2023-03-08 thomas #ifndef HAVE_SIPHASH
205 47dc83f5 2023-03-08 thomas #include "compat/siphash.h"
206 4fccd2fe 2023-03-08 thomas #else
207 4fccd2fe 2023-03-08 thomas #include <siphash.h>
208 47dc83f5 2023-03-08 thomas #endif
209 47dc83f5 2023-03-08 thomas
210 47dc83f5 2023-03-08 thomas /* Include Apple-specific headers. Mostly for crypto.*/
211 47dc83f5 2023-03-08 thomas #if defined(__APPLE__)
212 47dc83f5 2023-03-08 thomas #define COMMON_DIGEST_FOR_OPENSSL
213 47dc83f5 2023-03-08 thomas #include <CommonCrypto/CommonDigest.h>
214 47dc83f5 2023-03-08 thomas
215 47dc83f5 2023-03-08 thomas #define SHA512_BLOCK_LENGTH 128
216 47dc83f5 2023-03-08 thomas typedef struct _SHA2_CTX {
217 47dc83f5 2023-03-08 thomas union {
218 47dc83f5 2023-03-08 thomas u_int32_t st32[8];
219 47dc83f5 2023-03-08 thomas u_int64_t st64[8];
220 47dc83f5 2023-03-08 thomas } state;
221 47dc83f5 2023-03-08 thomas u_int64_t bitcount[2];
222 47dc83f5 2023-03-08 thomas u_int8_t buffer[SHA512_BLOCK_LENGTH];
223 47dc83f5 2023-03-08 thomas } SHA2_CTX;
224 68069cf6 2023-03-08 thomas #endif
225 68069cf6 2023-03-08 thomas
226 68069cf6 2023-03-08 thomas #if defined(__APPLE__) || defined(__NetBSD__)
227 47dc83f5 2023-03-08 thomas #define SHA256Init SHA256_Init
228 47dc83f5 2023-03-08 thomas #define SHA256Update SHA256_Update
229 47dc83f5 2023-03-08 thomas #define SHA256Final SHA256_Final
230 47dc83f5 2023-03-08 thomas #endif
231 47dc83f5 2023-03-08 thomas
232 47dc83f5 2023-03-08 thomas #ifndef __APPLE__
233 d9b944c7 2023-03-08 thomas #ifdef HAVE_SHA_H
234 47dc83f5 2023-03-08 thomas # include <sha.h>
235 47dc83f5 2023-03-08 thomas #endif
236 d9b944c7 2023-03-08 thomas #ifdef HAVE_SHA1_H
237 47dc83f5 2023-03-08 thomas # include <sha1.h>
238 47dc83f5 2023-03-08 thomas #endif
239 40d53943 2023-03-08 thomas #ifdef HAVE_SHA2_H
240 47dc83f5 2023-03-08 thomas # include <sha2.h>
241 47dc83f5 2023-03-08 thomas #else
242 47dc83f5 2023-03-08 thomas # include "sha2.h"
243 47dc83f5 2023-03-08 thomas #endif
244 40d53943 2023-03-08 thomas #ifdef HAVE_SHA256_H
245 47dc83f5 2023-03-08 thomas # include <sha256.h>
246 47dc83f5 2023-03-08 thomas #endif
247 47dc83f5 2023-03-08 thomas #endif
248 47dc83f5 2023-03-08 thomas
249 47dc83f5 2023-03-08 thomas /* Catch-all for systems where the header files don't exist and/or the below
250 47dc83f5 2023-03-08 thomas * still are not defined.
251 47dc83f5 2023-03-08 thomas */
252 47dc83f5 2023-03-08 thomas #ifndef SHA256_DIGEST_LENGTH
253 47dc83f5 2023-03-08 thomas #define SHA256_DIGEST_LENGTH 32
254 47dc83f5 2023-03-08 thomas #endif
255 47dc83f5 2023-03-08 thomas
256 47dc83f5 2023-03-08 thomas #ifndef SHA256_DIGEST_STRING_LENGTH
257 47dc83f5 2023-03-08 thomas #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
258 47dc83f5 2023-03-08 thomas #endif
259 47dc83f5 2023-03-08 thomas
260 47dc83f5 2023-03-08 thomas #if defined(__DragonFly__)
261 47dc83f5 2023-03-08 thomas #include <openssl/sha.h>
262 47dc83f5 2023-03-08 thomas #endif
263 47dc83f5 2023-03-08 thomas
264 47dc83f5 2023-03-08 thomas #ifndef SHA1_DIGEST_LENGTH
265 47dc83f5 2023-03-08 thomas #define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
266 47dc83f5 2023-03-08 thomas #define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
267 47dc83f5 2023-03-08 thomas
268 47dc83f5 2023-03-08 thomas #define SHA1_CTX SHA_CTX
269 47dc83f5 2023-03-08 thomas #define SHA1Init SHA1_Init
270 47dc83f5 2023-03-08 thomas #define SHA1Update SHA1_Update
271 47dc83f5 2023-03-08 thomas #define SHA1Final SHA1_Final
272 47dc83f5 2023-03-08 thomas #endif
273 47dc83f5 2023-03-08 thomas
274 47dc83f5 2023-03-08 thomas /*
275 47dc83f5 2023-03-08 thomas * The following SA_LEN/SS_LEN dance comes from various source, notably
276 47dc83f5 2023-03-08 thomas * OpenSMTP by way of OpenNTPD and OpenBGPD (thanks everyone!). got-portable
277 47dc83f5 2023-03-08 thomas * has tweaked a lot of the following macros to suit the needs of
278 47dc83f5 2023-03-08 thomas * got-portable.
279 47dc83f5 2023-03-08 thomas */
280 47dc83f5 2023-03-08 thomas
281 47dc83f5 2023-03-08 thomas /* From OpenNTPD portable */
282 47dc83f5 2023-03-08 thomas #if !defined(SA_LEN)
283 47dc83f5 2023-03-08 thomas # if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
284 47dc83f5 2023-03-08 thomas # define SA_LEN(x) ((x)->sa_len)
285 47dc83f5 2023-03-08 thomas # else
286 47dc83f5 2023-03-08 thomas # define SA_LEN(x) ((x)->sa_family == AF_INET6 ? \
287 47dc83f5 2023-03-08 thomas sizeof(struct sockaddr_in6) : \
288 47dc83f5 2023-03-08 thomas sizeof(struct sockaddr_in))
289 47dc83f5 2023-03-08 thomas # endif
290 47dc83f5 2023-03-08 thomas
291 47dc83f5 2023-03-08 thomas #endif
292 47dc83f5 2023-03-08 thomas
293 47dc83f5 2023-03-08 thomas /* From OpenBGPD portable */
294 47dc83f5 2023-03-08 thomas #if !defined(SS_LEN)
295 47dc83f5 2023-03-08 thomas # if defined(HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN)
296 47dc83f5 2023-03-08 thomas # define SS_LEN(x) ((x)->ss_len)
297 47dc83f5 2023-03-08 thomas # else
298 47dc83f5 2023-03-08 thomas # define SS_LEN(x) SA_LEN((struct sockaddr *)(x))
299 47dc83f5 2023-03-08 thomas # endif
300 47dc83f5 2023-03-08 thomas #endif
301 47dc83f5 2023-03-08 thomas
302 4fccd2fe 2023-03-08 thomas /* SOCK_NONBLOCK isn't available across BSDs... */
303 4fccd2fe 2023-03-08 thomas #if !defined(SOCK_NONBLOCK) && !defined(__linux__)
304 4fccd2fe 2023-03-08 thomas #define SOCK_NONBLOCK 00004000
305 4fccd2fe 2023-03-08 thomas #endif
306 4fccd2fe 2023-03-08 thomas
307 47dc83f5 2023-03-08 thomas #ifndef HAVE_ASPRINTF
308 47dc83f5 2023-03-08 thomas /* asprintf.c */
309 47dc83f5 2023-03-08 thomas int asprintf(char **, const char *, ...);
310 47dc83f5 2023-03-08 thomas int vasprintf(char **, const char *, va_list);
311 47dc83f5 2023-03-08 thomas #endif
312 47dc83f5 2023-03-08 thomas
313 47dc83f5 2023-03-08 thomas #ifndef HAVE_EXPLICIT_BZERO
314 47dc83f5 2023-03-08 thomas /* explicit_bzero.c */
315 47dc83f5 2023-03-08 thomas void explicit_bzero(void *, size_t);
316 47dc83f5 2023-03-08 thomas #endif
317 47dc83f5 2023-03-08 thomas
318 47dc83f5 2023-03-08 thomas #ifndef HAVE_GETDTABLECOUNT
319 47dc83f5 2023-03-08 thomas /* getdtablecount.c */
320 47dc83f5 2023-03-08 thomas int getdtablecount(void);
321 47dc83f5 2023-03-08 thomas #endif
322 47dc83f5 2023-03-08 thomas
323 47dc83f5 2023-03-08 thomas #ifndef HAVE_CLOSEFROM
324 47dc83f5 2023-03-08 thomas /* closefrom.c */
325 47dc83f5 2023-03-08 thomas void closefrom(int);
326 47dc83f5 2023-03-08 thomas #endif
327 47dc83f5 2023-03-08 thomas
328 47dc83f5 2023-03-08 thomas #ifndef HAVE_STRSEP
329 47dc83f5 2023-03-08 thomas /* strsep.c */
330 47dc83f5 2023-03-08 thomas char *strsep(char **, const char *);
331 47dc83f5 2023-03-08 thomas #endif
332 47dc83f5 2023-03-08 thomas
333 47dc83f5 2023-03-08 thomas #ifndef HAVE_STRTONUM
334 47dc83f5 2023-03-08 thomas /* strtonum.c */
335 47dc83f5 2023-03-08 thomas long long strtonum(const char *, long long, long long, const char **);
336 47dc83f5 2023-03-08 thomas #endif
337 47dc83f5 2023-03-08 thomas
338 47dc83f5 2023-03-08 thomas #ifndef HAVE_STRLCPY
339 47dc83f5 2023-03-08 thomas /* strlcpy.c */
340 47dc83f5 2023-03-08 thomas size_t strlcpy(char *, const char *, size_t);
341 47dc83f5 2023-03-08 thomas #endif
342 47dc83f5 2023-03-08 thomas
343 47dc83f5 2023-03-08 thomas #ifndef HAVE_STRLCAT
344 47dc83f5 2023-03-08 thomas /* strlcat.c */
345 47dc83f5 2023-03-08 thomas size_t strlcat(char *, const char *, size_t);
346 47dc83f5 2023-03-08 thomas #endif
347 47dc83f5 2023-03-08 thomas
348 47dc83f5 2023-03-08 thomas #ifndef HAVE_STRNLEN
349 47dc83f5 2023-03-08 thomas /* strnlen.c */
350 47dc83f5 2023-03-08 thomas size_t strnlen(const char *, size_t);
351 47dc83f5 2023-03-08 thomas #endif
352 47dc83f5 2023-03-08 thomas
353 47dc83f5 2023-03-08 thomas #ifndef HAVE_STRNDUP
354 47dc83f5 2023-03-08 thomas /* strndup.c */
355 47dc83f5 2023-03-08 thomas char *strndup(const char *, size_t);
356 47dc83f5 2023-03-08 thomas #endif
357 47dc83f5 2023-03-08 thomas
358 47dc83f5 2023-03-08 thomas #ifndef HAVE_GETPROGNAME
359 47dc83f5 2023-03-08 thomas /* getprogname.c */
360 47dc83f5 2023-03-08 thomas const char *getprogname(void);
361 47dc83f5 2023-03-08 thomas #endif
362 47dc83f5 2023-03-08 thomas
363 47dc83f5 2023-03-08 thomas #ifndef HAVE_GETLINE
364 47dc83f5 2023-03-08 thomas /* getline.c */
365 47dc83f5 2023-03-08 thomas ssize_t getline(char **, size_t *, FILE *);
366 47dc83f5 2023-03-08 thomas #endif
367 47dc83f5 2023-03-08 thomas
368 47dc83f5 2023-03-08 thomas #ifndef HAVE_FREEZERO
369 47dc83f5 2023-03-08 thomas /* freezero.c */
370 47dc83f5 2023-03-08 thomas void freezero(void *, size_t);
371 47dc83f5 2023-03-08 thomas #endif
372 47dc83f5 2023-03-08 thomas
373 47dc83f5 2023-03-08 thomas #ifndef HAVE_GETDTABLECOUNT
374 47dc83f5 2023-03-08 thomas /* getdtablecount.c */
375 47dc83f5 2023-03-08 thomas int getdtablecount(void);
376 47dc83f5 2023-03-08 thomas #endif
377 47dc83f5 2023-03-08 thomas
378 47dc83f5 2023-03-08 thomas #ifndef HAVE_REALLOCARRAY
379 47dc83f5 2023-03-08 thomas /* reallocarray.c */
380 47dc83f5 2023-03-08 thomas void *reallocarray(void *, size_t, size_t);
381 47dc83f5 2023-03-08 thomas #endif
382 47dc83f5 2023-03-08 thomas
383 47dc83f5 2023-03-08 thomas #ifndef HAVE_RECALLOCARRAY
384 47dc83f5 2023-03-08 thomas /* recallocarray.c */
385 47dc83f5 2023-03-08 thomas void *recallocarray(void *, size_t, size_t, size_t);
386 47dc83f5 2023-03-08 thomas #endif
387 47dc83f5 2023-03-08 thomas
388 47dc83f5 2023-03-08 thomas #ifndef HAVE_SETPROCTITLE
389 47dc83f5 2023-03-08 thomas /* setproctitle.c */
390 47dc83f5 2023-03-08 thomas void setproctitle(const char *, ...);
391 47dc83f5 2023-03-08 thomas #endif
392 47dc83f5 2023-03-08 thomas
393 47dc83f5 2023-03-08 thomas #ifndef HAVE_FMT_SCALED
394 47dc83f5 2023-03-08 thomas /* fmt_scaled.c */
395 47dc83f5 2023-03-08 thomas int fmt_scaled(long long, char *);
396 47dc83f5 2023-03-08 thomas int scan_scaled(char *, long long *);
397 47dc83f5 2023-03-08 thomas #define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
398 47dc83f5 2023-03-08 thomas #endif
399 47dc83f5 2023-03-08 thomas
400 8d60d668 2023-03-16 thomas #if !defined(HAVE_LIBBSD) && !defined(HAVE_GETOPT_OPTRESET)
401 47dc83f5 2023-03-08 thomas /* getopt.c */
402 47dc83f5 2023-03-08 thomas extern int BSDopterr;
403 47dc83f5 2023-03-08 thomas extern int BSDoptind;
404 47dc83f5 2023-03-08 thomas extern int BSDoptopt;
405 47dc83f5 2023-03-08 thomas extern int BSDoptreset;
406 47dc83f5 2023-03-08 thomas extern char *BSDoptarg;
407 47dc83f5 2023-03-08 thomas int BSDgetopt(int, char *const *, const char *);
408 47dc83f5 2023-03-08 thomas #define getopt(ac, av, o) BSDgetopt(ac, av, o)
409 47dc83f5 2023-03-08 thomas #define opterr BSDopterr
410 47dc83f5 2023-03-08 thomas #define optind BSDoptind
411 47dc83f5 2023-03-08 thomas #define optopt BSDoptopt
412 47dc83f5 2023-03-08 thomas #define optreset BSDoptreset
413 47dc83f5 2023-03-08 thomas #define optarg BSDoptarg
414 47dc83f5 2023-03-08 thomas #endif
415 47dc83f5 2023-03-08 thomas
416 47dc83f5 2023-03-08 thomas /* Check for some of the non-portable timespec*() functions.
417 47dc83f5 2023-03-08 thomas * This should largely come from libbsd for systems which
418 47dc83f5 2023-03-08 thomas * aren't BSD, but this will depend on how old the library
419 47dc83f5 2023-03-08 thomas * is.
420 47dc83f5 2023-03-08 thomas */
421 47dc83f5 2023-03-08 thomas #ifndef timespecisset
422 47dc83f5 2023-03-08 thomas #define timespecisset(tsp) \
423 47dc83f5 2023-03-08 thomas ((tsp)->tv_sec || (tsp)->tv_nsec)
424 47dc83f5 2023-03-08 thomas #endif
425 47dc83f5 2023-03-08 thomas
426 47dc83f5 2023-03-08 thomas #ifndef timespecsub
427 47dc83f5 2023-03-08 thomas #define timespecsub(tsp, usp, vsp) \
428 47dc83f5 2023-03-08 thomas do { \
429 47dc83f5 2023-03-08 thomas (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
430 47dc83f5 2023-03-08 thomas (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
431 47dc83f5 2023-03-08 thomas if ((vsp)->tv_nsec < 0) { \
432 47dc83f5 2023-03-08 thomas (vsp)->tv_sec--; \
433 47dc83f5 2023-03-08 thomas (vsp)->tv_nsec += 1000000000L; \
434 47dc83f5 2023-03-08 thomas } \
435 47dc83f5 2023-03-08 thomas } while (0)
436 47dc83f5 2023-03-08 thomas #endif
437 47dc83f5 2023-03-08 thomas
438 47dc83f5 2023-03-08 thomas #ifndef timespeccmp
439 47dc83f5 2023-03-08 thomas #define timespeccmp(tvp, uvp, cmp) \
440 47dc83f5 2023-03-08 thomas (((tvp)->tv_sec == (uvp)->tv_sec) ? \
441 47dc83f5 2023-03-08 thomas ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \
442 47dc83f5 2023-03-08 thomas ((tvp)->tv_sec cmp (uvp)->tv_sec))
443 47dc83f5 2023-03-08 thomas #endif
444 47dc83f5 2023-03-08 thomas
445 4fccd2fe 2023-03-08 thomas #ifndef HAVE_MERGESORT
446 47dc83f5 2023-03-08 thomas /* mergesort.c */
447 47dc83f5 2023-03-08 thomas int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
448 47dc83f5 2023-03-08 thomas #endif
449 1ef7c68a 2023-03-08 thomas #endif