2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include <sys/types.h>
32 #elif HAVE_SYS_ENDIAN_H
33 # include <sys/endian.h>
34 #elif HAVE_LIBKERN_OSBYTEORDER_H
35 # include <machine/endian.h>
36 # include <libkern/OSByteOrder.h>
38 # define htobe16(x) OSSwapHostToBigInt16(x)
39 # define htole16(x) OSSwapHostToLittleInt16(x)
40 # define be16toh(x) OSSwapBigToHostInt16(x)
41 # define le16toh(x) OSSwapLittleToHostInt16(x)
43 # define htobe32(x) OSSwapHostToBigInt32(x)
44 # define htole32(x) OSSwapHostToLittleInt32(x)
45 # define be32toh(x) OSSwapBigToHostInt32(x)
46 # define le32toh(x) OSSwapLittleToHostInt32(x)
48 # define htobe64(x) OSSwapHostToBigInt64(x)
49 # define htole64(x) OSSwapHostToLittleInt64(x)
50 # define be64toh(x) OSSwapBigToHostInt64(x)
51 # define le64toh(x) OSSwapLittleToHostInt64(x)
53 # error no compatible endian.h header found
57 # include <sys/queue.h>
59 # include "compat/queue.h"
65 # include "compat/imsg.h"
72 # include "compat/ohash.h"
73 # define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
74 int scan_scaled(char *, long long *);
75 int fmt_scaled(long long, char *);
79 int asprintf(char**, const char*, ...);
80 int vasprintf(char**, const char*, va_list);
84 void err(int, const char*, ...);
85 void errx(int, const char*, ...);
86 void warn(int, const char*, ...);
87 void warnx(int, const char*, ...);
92 #ifndef HAVE_EXPLICIT_BZERO
93 void explicit_bzero(void *, size_t);
97 void freezero(void*, size_t);
100 #ifndef HAVE_GETDTABLECOUNT
101 int getdtablecount(void);
104 #ifndef HAVE_GETDTABLESIZE
105 int getdtablesize(void);
109 char *fgetln(FILE *, size_t *);
112 #ifndef HAVE_FPARSELN
113 char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
116 #ifndef HAVE_GETPROGNAME
117 const char *getprogname(void);
120 #ifdef HAVE_LIBUTIL_H
125 void *memmem(const void*, size_t, const void*, size_t);
128 #ifndef HAVE_REALLOCARRAY
129 void *reallocarray(void*, size_t, size_t);
132 #ifndef HAVE_RECALLOCARRAY
133 void *recallocarray(void*, size_t, size_t, size_t);
136 #ifndef HAVE_STRCASESTR
137 char *strcasestr(const char *, const char *);
141 size_t strlcpy(char*, const char*, size_t);
145 size_t strlcat(char*, const char*, size_t);
149 char *strsep(char**, const char*);
152 #ifndef HAVE_STRTONUM
153 long long strtonum(const char*, long long, long long, const char**);
156 #ifndef HAVE_SETPROCTITLE
157 void setproctitle(const char*, ...);
160 /* Needed for Darwin (MacOS) to keep fparseln() happy -- but could also be
161 * used elsewhere in the future.
168 #define __dead __attribute__((__noreturn__))
172 * The following time-related macros from sys/time.h are subject to:
174 * Copyright (c) 1982, 1986, 1993
175 * The Regents of the University of California. All rights reserved.
177 * Redistribution and use in source and binary forms, with or without
178 * modification, are permitted provided that the following conditions
180 * 1. Redistributions of source code must retain the above copyright
181 * notice, this list of conditions and the following disclaimer.
182 * 2. Redistributions in binary form must reproduce the above copyright
183 * notice, this list of conditions and the following disclaimer in the
184 * documentation and/or other materials provided with the distribution.
185 * 3. Neither the name of the University nor the names of its contributors
186 * may be used to endorse or promote products derived from this software
187 * without specific prior written permission.
189 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
190 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
192 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
193 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
194 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
195 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
196 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
197 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
198 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
201 * @(#)time.h 8.2 (Berkeley) 7/10/94
204 #ifndef HAVE_TIMESPECSUB
205 #define timespecsub(tsp, usp, vsp) \
207 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
208 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
209 if ((vsp)->tv_nsec < 0) { \
211 (vsp)->tv_nsec += 1000000000L; \
216 #ifndef HAVE_TIMERCMP
217 #define timercmp(tvp, uvp, cmp) \
218 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
219 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
220 ((tvp)->tv_sec cmp (uvp)->tv_sec))
223 #ifndef HAVE_TIMEVAL_TO_TIMESPEC
224 #define TIMEVAL_TO_TIMESPEC(tv, ts) do { \
225 (ts)->tv_sec = (tv)->tv_sec; \
226 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
228 #define TIMESPEC_TO_TIMEVAL(tv, ts) do { \
229 (tv)->tv_sec = (ts)->tv_sec; \
230 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
234 #endif /* COMPAT_H */