Blame


1 6ab857d5 2024-01-23 op /*
2 6ab857d5 2024-01-23 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 6ab857d5 2024-01-23 op *
4 6ab857d5 2024-01-23 op * Permission to use, copy, modify, and distribute this software for any
5 6ab857d5 2024-01-23 op * purpose with or without fee is hereby granted, provided that the above
6 6ab857d5 2024-01-23 op * copyright notice and this permission notice appear in all copies.
7 6ab857d5 2024-01-23 op *
8 6ab857d5 2024-01-23 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 6ab857d5 2024-01-23 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 6ab857d5 2024-01-23 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 6ab857d5 2024-01-23 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 6ab857d5 2024-01-23 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 6ab857d5 2024-01-23 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 6ab857d5 2024-01-23 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 6ab857d5 2024-01-23 op */
16 6ab857d5 2024-01-23 op
17 6ab857d5 2024-01-23 op #ifndef COMPAT_H
18 6ab857d5 2024-01-23 op #define COMPAT_H
19 6ab857d5 2024-01-23 op
20 6ab857d5 2024-01-23 op #include "config.h"
21 6ab857d5 2024-01-23 op
22 6ab857d5 2024-01-23 op #include <sys/types.h>
23 6ab857d5 2024-01-23 op #include <sys/uio.h>
24 6ab857d5 2024-01-23 op
25 6ab857d5 2024-01-23 op #include <stdarg.h>
26 6ab857d5 2024-01-23 op #include <stddef.h>
27 6ab857d5 2024-01-23 op #include <stdint.h>
28 e234161f 2024-06-12 thomas.ad #include <stdio.h>
29 6ab857d5 2024-01-23 op
30 6ab857d5 2024-01-23 op #if HAVE_ENDIAN_H
31 6ab857d5 2024-01-23 op # include <endian.h>
32 6ab857d5 2024-01-23 op #elif HAVE_SYS_ENDIAN_H
33 6ab857d5 2024-01-23 op # include <sys/endian.h>
34 6ab857d5 2024-01-23 op #elif HAVE_LIBKERN_OSBYTEORDER_H
35 6ab857d5 2024-01-23 op # include <machine/endian.h>
36 6ab857d5 2024-01-23 op # include <libkern/OSByteOrder.h>
37 6ab857d5 2024-01-23 op
38 6ab857d5 2024-01-23 op # define htobe16(x) OSSwapHostToBigInt16(x)
39 6ab857d5 2024-01-23 op # define htole16(x) OSSwapHostToLittleInt16(x)
40 6ab857d5 2024-01-23 op # define be16toh(x) OSSwapBigToHostInt16(x)
41 6ab857d5 2024-01-23 op # define le16toh(x) OSSwapLittleToHostInt16(x)
42 6ab857d5 2024-01-23 op
43 6ab857d5 2024-01-23 op # define htobe32(x) OSSwapHostToBigInt32(x)
44 6ab857d5 2024-01-23 op # define htole32(x) OSSwapHostToLittleInt32(x)
45 6ab857d5 2024-01-23 op # define be32toh(x) OSSwapBigToHostInt32(x)
46 6ab857d5 2024-01-23 op # define le32toh(x) OSSwapLittleToHostInt32(x)
47 6ab857d5 2024-01-23 op
48 6ab857d5 2024-01-23 op # define htobe64(x) OSSwapHostToBigInt64(x)
49 6ab857d5 2024-01-23 op # define htole64(x) OSSwapHostToLittleInt64(x)
50 6ab857d5 2024-01-23 op # define be64toh(x) OSSwapBigToHostInt64(x)
51 6ab857d5 2024-01-23 op # define le64toh(x) OSSwapLittleToHostInt64(x)
52 6ab857d5 2024-01-23 op #else
53 6ab857d5 2024-01-23 op # error no compatible endian.h header found
54 6ab857d5 2024-01-23 op #endif
55 6ab857d5 2024-01-23 op
56 6ab857d5 2024-01-23 op #ifdef HAVE_QUEUE_H
57 6ab857d5 2024-01-23 op # include <sys/queue.h>
58 6ab857d5 2024-01-23 op #else
59 6ab857d5 2024-01-23 op # include "compat/queue.h"
60 6ab857d5 2024-01-23 op #endif
61 6ab857d5 2024-01-23 op
62 6ab857d5 2024-01-23 op #ifdef HAVE_IMSG
63 6ab857d5 2024-01-23 op # include <imsg.h>
64 6ab857d5 2024-01-23 op #else
65 6ab857d5 2024-01-23 op # include "compat/imsg.h"
66 6ab857d5 2024-01-23 op #endif
67 6ab857d5 2024-01-23 op
68 6ab857d5 2024-01-23 op #ifdef HAVE_LIBUTIL
69 6ab857d5 2024-01-23 op # include <ohash.h>
70 6ab857d5 2024-01-23 op # include <util.h>
71 6ab857d5 2024-01-23 op #else
72 6ab857d5 2024-01-23 op # include "compat/ohash.h"
73 6ab857d5 2024-01-23 op # define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
74 6ab857d5 2024-01-23 op int scan_scaled(char *, long long *);
75 6ab857d5 2024-01-23 op int fmt_scaled(long long, char *);
76 6ab857d5 2024-01-23 op #endif
77 6ab857d5 2024-01-23 op
78 6ab857d5 2024-01-23 op #ifndef HAVE_ASPRINTF
79 6ab857d5 2024-01-23 op int asprintf(char**, const char*, ...);
80 6ab857d5 2024-01-23 op int vasprintf(char**, const char*, va_list);
81 6ab857d5 2024-01-23 op #endif
82 6ab857d5 2024-01-23 op
83 6ab857d5 2024-01-23 op #ifndef HAVE_ERR
84 6ab857d5 2024-01-23 op void err(int, const char*, ...);
85 6ab857d5 2024-01-23 op void errx(int, const char*, ...);
86 6ab857d5 2024-01-23 op void warn(int, const char*, ...);
87 6ab857d5 2024-01-23 op void warnx(int, const char*, ...);
88 6ab857d5 2024-01-23 op #else
89 6ab857d5 2024-01-23 op # include <err.h>
90 6ab857d5 2024-01-23 op #endif
91 6ab857d5 2024-01-23 op
92 6ab857d5 2024-01-23 op #ifndef HAVE_EXPLICIT_BZERO
93 6ab857d5 2024-01-23 op void explicit_bzero(void *, size_t);
94 6ab857d5 2024-01-23 op #endif
95 6ab857d5 2024-01-23 op
96 6ab857d5 2024-01-23 op #ifndef HAVE_FREEZERO
97 6ab857d5 2024-01-23 op void freezero(void*, size_t);
98 6ab857d5 2024-01-23 op #endif
99 6ab857d5 2024-01-23 op
100 6ab857d5 2024-01-23 op #ifndef HAVE_GETDTABLECOUNT
101 6ab857d5 2024-01-23 op int getdtablecount(void);
102 6ab857d5 2024-01-23 op #endif
103 6ab857d5 2024-01-23 op
104 6ab857d5 2024-01-23 op #ifndef HAVE_GETDTABLESIZE
105 6ab857d5 2024-01-23 op int getdtablesize(void);
106 6ab857d5 2024-01-23 op #endif
107 6ab857d5 2024-01-23 op
108 e234161f 2024-06-12 thomas.ad #ifndef HAVE_FGETLN
109 e234161f 2024-06-12 thomas.ad char *fgetln(FILE *, size_t *);
110 e234161f 2024-06-12 thomas.ad #endif
111 e234161f 2024-06-12 thomas.ad
112 e234161f 2024-06-12 thomas.ad #ifndef HAVE_FPARSELN
113 e234161f 2024-06-12 thomas.ad char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
114 e234161f 2024-06-12 thomas.ad #endif
115 e234161f 2024-06-12 thomas.ad
116 6ab857d5 2024-01-23 op #ifndef HAVE_GETPROGNAME
117 6ab857d5 2024-01-23 op const char *getprogname(void);
118 6ab857d5 2024-01-23 op #endif
119 6ab857d5 2024-01-23 op
120 e234161f 2024-06-12 thomas.ad #ifdef HAVE_LIBUTIL_H
121 e234161f 2024-06-12 thomas.ad #include <libutil.h>
122 e234161f 2024-06-12 thomas.ad #endif
123 e234161f 2024-06-12 thomas.ad
124 6ab857d5 2024-01-23 op #ifndef HAVE_MEMMEM
125 6ab857d5 2024-01-23 op void *memmem(const void*, size_t, const void*, size_t);
126 6ab857d5 2024-01-23 op #endif
127 6ab857d5 2024-01-23 op
128 abe0273c 2024-02-06 op #ifndef HAVE_REALLOCARRAY
129 abe0273c 2024-02-06 op void *reallocarray(void*, size_t, size_t);
130 abe0273c 2024-02-06 op #endif
131 abe0273c 2024-02-06 op
132 6ab857d5 2024-01-23 op #ifndef HAVE_RECALLOCARRAY
133 6ab857d5 2024-01-23 op void *recallocarray(void*, size_t, size_t, size_t);
134 6ab857d5 2024-01-23 op #endif
135 6ab857d5 2024-01-23 op
136 6ab857d5 2024-01-23 op #ifndef HAVE_STRCASESTR
137 6ab857d5 2024-01-23 op char *strcasestr(const char *, const char *);
138 6ab857d5 2024-01-23 op #endif
139 6ab857d5 2024-01-23 op
140 6ab857d5 2024-01-23 op #ifndef HAVE_STRLCPY
141 6ab857d5 2024-01-23 op size_t strlcpy(char*, const char*, size_t);
142 6ab857d5 2024-01-23 op #endif
143 6ab857d5 2024-01-23 op
144 6ab857d5 2024-01-23 op #ifndef HAVE_STRLCAT
145 6ab857d5 2024-01-23 op size_t strlcat(char*, const char*, size_t);
146 6ab857d5 2024-01-23 op #endif
147 6ab857d5 2024-01-23 op
148 6ab857d5 2024-01-23 op #ifndef HAVE_STRSEP
149 6ab857d5 2024-01-23 op char *strsep(char**, const char*);
150 6ab857d5 2024-01-23 op #endif
151 6ab857d5 2024-01-23 op
152 6ab857d5 2024-01-23 op #ifndef HAVE_STRTONUM
153 6ab857d5 2024-01-23 op long long strtonum(const char*, long long, long long, const char**);
154 6ab857d5 2024-01-23 op #endif
155 6ab857d5 2024-01-23 op
156 6ab857d5 2024-01-23 op #ifndef HAVE_SETPROCTITLE
157 6ab857d5 2024-01-23 op void setproctitle(const char*, ...);
158 6ab857d5 2024-01-23 op #endif
159 6ab857d5 2024-01-23 op
160 16c7aa4b 2024-06-14 thomas.ad /* Needed for Darwin (MacOS) to keep fparseln() happy -- but could also be
161 16c7aa4b 2024-06-14 thomas.ad * used elsewhere in the future.
162 16c7aa4b 2024-06-14 thomas.ad */
163 16c7aa4b 2024-06-14 thomas.ad #ifdef HAVE_UTIL_H
164 16c7aa4b 2024-06-14 thomas.ad #include <util.h>
165 16c7aa4b 2024-06-14 thomas.ad #endif
166 16c7aa4b 2024-06-14 thomas.ad
167 029a63f4 2024-02-19 op #ifndef __dead
168 029a63f4 2024-02-19 op #define __dead __attribute__((__noreturn__))
169 029a63f4 2024-02-19 op #endif
170 029a63f4 2024-02-19 op
171 b45ef13d 2024-02-19 op /*
172 b45ef13d 2024-02-19 op * The following time-related macros from sys/time.h are subject to:
173 b45ef13d 2024-02-19 op *
174 b45ef13d 2024-02-19 op * Copyright (c) 1982, 1986, 1993
175 b45ef13d 2024-02-19 op * The Regents of the University of California. All rights reserved.
176 b45ef13d 2024-02-19 op *
177 b45ef13d 2024-02-19 op * Redistribution and use in source and binary forms, with or without
178 b45ef13d 2024-02-19 op * modification, are permitted provided that the following conditions
179 b45ef13d 2024-02-19 op * are met:
180 b45ef13d 2024-02-19 op * 1. Redistributions of source code must retain the above copyright
181 b45ef13d 2024-02-19 op * notice, this list of conditions and the following disclaimer.
182 b45ef13d 2024-02-19 op * 2. Redistributions in binary form must reproduce the above copyright
183 b45ef13d 2024-02-19 op * notice, this list of conditions and the following disclaimer in the
184 b45ef13d 2024-02-19 op * documentation and/or other materials provided with the distribution.
185 b45ef13d 2024-02-19 op * 3. Neither the name of the University nor the names of its contributors
186 b45ef13d 2024-02-19 op * may be used to endorse or promote products derived from this software
187 b45ef13d 2024-02-19 op * without specific prior written permission.
188 b45ef13d 2024-02-19 op *
189 b45ef13d 2024-02-19 op * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
190 b45ef13d 2024-02-19 op * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191 b45ef13d 2024-02-19 op * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
192 b45ef13d 2024-02-19 op * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
193 b45ef13d 2024-02-19 op * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
194 b45ef13d 2024-02-19 op * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
195 b45ef13d 2024-02-19 op * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
196 b45ef13d 2024-02-19 op * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
197 b45ef13d 2024-02-19 op * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
198 b45ef13d 2024-02-19 op * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199 b45ef13d 2024-02-19 op * SUCH DAMAGE.
200 b45ef13d 2024-02-19 op *
201 b45ef13d 2024-02-19 op * @(#)time.h 8.2 (Berkeley) 7/10/94
202 b45ef13d 2024-02-19 op */
203 b45ef13d 2024-02-19 op
204 b45ef13d 2024-02-19 op #ifndef HAVE_TIMESPECSUB
205 b45ef13d 2024-02-19 op #define timespecsub(tsp, usp, vsp) \
206 b45ef13d 2024-02-19 op do { \
207 b45ef13d 2024-02-19 op (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
208 b45ef13d 2024-02-19 op (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
209 b45ef13d 2024-02-19 op if ((vsp)->tv_nsec < 0) { \
210 b45ef13d 2024-02-19 op (vsp)->tv_sec--; \
211 b45ef13d 2024-02-19 op (vsp)->tv_nsec += 1000000000L; \
212 b45ef13d 2024-02-19 op } \
213 b45ef13d 2024-02-19 op } while (0)
214 b45ef13d 2024-02-19 op #endif
215 b45ef13d 2024-02-19 op
216 b45ef13d 2024-02-19 op #ifndef HAVE_TIMERCMP
217 b45ef13d 2024-02-19 op #define timercmp(tvp, uvp, cmp) \
218 b45ef13d 2024-02-19 op (((tvp)->tv_sec == (uvp)->tv_sec) ? \
219 b45ef13d 2024-02-19 op ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
220 b45ef13d 2024-02-19 op ((tvp)->tv_sec cmp (uvp)->tv_sec))
221 b45ef13d 2024-02-19 op #endif
222 b45ef13d 2024-02-19 op
223 b45ef13d 2024-02-19 op #ifndef HAVE_TIMEVAL_TO_TIMESPEC
224 b45ef13d 2024-02-19 op #define TIMEVAL_TO_TIMESPEC(tv, ts) do { \
225 b45ef13d 2024-02-19 op (ts)->tv_sec = (tv)->tv_sec; \
226 b45ef13d 2024-02-19 op (ts)->tv_nsec = (tv)->tv_usec * 1000; \
227 b45ef13d 2024-02-19 op } while (0)
228 b45ef13d 2024-02-19 op #define TIMESPEC_TO_TIMEVAL(tv, ts) do { \
229 b45ef13d 2024-02-19 op (tv)->tv_sec = (ts)->tv_sec; \
230 b45ef13d 2024-02-19 op (tv)->tv_usec = (ts)->tv_nsec / 1000; \
231 b45ef13d 2024-02-19 op } while (0)
232 b45ef13d 2024-02-19 op #endif
233 b45ef13d 2024-02-19 op
234 6ab857d5 2024-01-23 op #endif /* COMPAT_H */