Blob


1 /*
2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 *
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.
7 *
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.
15 */
17 #ifndef COMPAT_H
18 #define COMPAT_H
20 #include "config.h"
22 #include <sys/types.h>
23 #include <sys/uio.h>
25 #include <stdarg.h>
26 #include <stddef.h>
27 #include <stdint.h>
29 #if HAVE_ENDIAN_H
30 # include <endian.h>
31 #elif HAVE_SYS_ENDIAN_H
32 # include <sys/endian.h>
33 #elif HAVE_LIBKERN_OSBYTEORDER_H
34 # include <machine/endian.h>
35 # include <libkern/OSByteOrder.h>
37 # define htobe16(x) OSSwapHostToBigInt16(x)
38 # define htole16(x) OSSwapHostToLittleInt16(x)
39 # define be16toh(x) OSSwapBigToHostInt16(x)
40 # define le16toh(x) OSSwapLittleToHostInt16(x)
42 # define htobe32(x) OSSwapHostToBigInt32(x)
43 # define htole32(x) OSSwapHostToLittleInt32(x)
44 # define be32toh(x) OSSwapBigToHostInt32(x)
45 # define le32toh(x) OSSwapLittleToHostInt32(x)
47 # define htobe64(x) OSSwapHostToBigInt64(x)
48 # define htole64(x) OSSwapHostToLittleInt64(x)
49 # define be64toh(x) OSSwapBigToHostInt64(x)
50 # define le64toh(x) OSSwapLittleToHostInt64(x)
51 #else
52 # error no compatible endian.h header found
53 #endif
55 #if HAVE_EVENT2
56 # include <event2/event.h>
57 # include <event2/event_compat.h>
58 # include <event2/event_struct.h>
59 # include <event2/buffer.h>
60 # include <event2/buffer_compat.h>
61 # include <event2/bufferevent.h>
62 # include <event2/bufferevent_struct.h>
63 # include <event2/bufferevent_compat.h>
64 #else
65 # include <event.h>
66 #endif
68 #ifdef HAVE_QUEUE_H
69 # include <sys/queue.h>
70 #else
71 # include "compat/queue.h"
72 #endif
74 #ifdef HAVE_IMSG
75 # include <imsg.h>
76 #else
77 # include "compat/imsg.h"
78 #endif
80 #ifdef HAVE_LIBUTIL
81 # include <ohash.h>
82 # include <util.h>
83 #else
84 # include "compat/ohash.h"
85 # define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
86 int scan_scaled(char *, long long *);
87 int fmt_scaled(long long, char *);
88 #endif
90 #ifndef HAVE_ASPRINTF
91 int asprintf(char**, const char*, ...);
92 int vasprintf(char**, const char*, va_list);
93 #endif
95 #ifndef HAVE_ERR
96 void err(int, const char*, ...);
97 void errx(int, const char*, ...);
98 void warn(int, const char*, ...);
99 void warnx(int, const char*, ...);
100 #else
101 # include <err.h>
102 #endif
104 #ifndef HAVE_EXPLICIT_BZERO
105 void explicit_bzero(void *, size_t);
106 #endif
108 #ifndef HAVE_FREEZERO
109 void freezero(void*, size_t);
110 #endif
112 #ifndef HAVE_GETDTABLECOUNT
113 int getdtablecount(void);
114 #endif
116 #ifndef HAVE_GETDTABLESIZE
117 int getdtablesize(void);
118 #endif
120 #ifndef HAVE_GETPROGNAME
121 const char *getprogname(void);
122 #endif
124 #ifndef HAVE_MEMMEM
125 void *memmem(const void*, size_t, const void*, size_t);
126 #endif
128 #ifndef HAVE_REALLOCARRAY
129 void *reallocarray(void*, size_t, size_t);
130 #endif
132 #ifndef HAVE_RECALLOCARRAY
133 void *recallocarray(void*, size_t, size_t, size_t);
134 #endif
136 #ifndef HAVE_STRCASESTR
137 char *strcasestr(const char *, const char *);
138 #endif
140 #ifndef HAVE_STRLCPY
141 size_t strlcpy(char*, const char*, size_t);
142 #endif
144 #ifndef HAVE_STRLCAT
145 size_t strlcat(char*, const char*, size_t);
146 #endif
148 #ifndef HAVE_STRSEP
149 char *strsep(char**, const char*);
150 #endif
152 #ifndef HAVE_STRTONUM
153 long long strtonum(const char*, long long, long long, const char**);
154 #endif
156 #ifndef HAVE_SETPROCTITLE
157 void setproctitle(const char*, ...);
158 #endif
160 #endif /* COMPAT_H */