Blob


1 #ifndef _GOT_COMPAT_H
2 #define _GOT_COMPAT_H
4 #include <sys/types.h>
5 #include <sys/ioctl.h>
6 #include <sys/uio.h>
7 #if defined(__FreeBSD__)
8 #include <sys/endian.h>
9 #else
10 #include <endian.h>
11 #endif
13 #include <fnmatch.h>
14 #include <limits.h>
15 #include <stdio.h>
16 #include <stdint.h>
18 /*
19 #include <termios.h>
20 #include <wchar.h>
21 */
23 /* For flock. */
24 #ifndef O_EXLOCK
25 #define O_EXLOCK 0
26 #endif
28 #ifndef HAVE_FLOCK
29 #define LOCK_SH 0
30 #define LOCK_EX 0
31 #define LOCK_NB 0
32 #define flock(fd, op) (0)
33 #else
34 #include <sys/file.h>
35 #endif
37 #ifndef __dead
38 #define __dead __attribute__ ((__noreturn__))
39 #endif
41 #ifndef __OpenBSD__
42 #define pledge(s, p) (0)
43 #define unveil(s, p) (0)
44 #endif
46 #ifdef HAVE_LINUX_LANDLOCK_H
47 int landlock_no_fs(void);
48 int landlock_unveil(const char *, const char *);
49 /* #undef unveil */
50 /* #define unveil(s, p) landlock_unveil((s), (p)) */
51 #endif
53 #ifndef INFTIM
54 #define INFTIM -1
55 #endif
57 #ifndef HAVE_BSD_UUID
58 #include <uuid/uuid.h>
59 #define uuid_s_ok 0
60 #define uuid_s_bad_version 1
61 #define uuid_s_invalid_string_uuid 2
62 #define uuid_s_no_memory 3
64 /* Length of a node address (an IEEE 802 address). */
65 #define _UUID_NODE_LEN 6
67 struct uuid {
68 uint32_t time_low;
69 uint16_t time_mid;
70 uint16_t time_hi_and_version;
71 uint8_t clock_seq_hi_and_reserved;
72 uint8_t clock_seq_low;
73 uint8_t node[_UUID_NODE_LEN];
74 };
76 int32_t uuid_equal(struct uuid *, struct uuid *, uint32_t *);
77 int32_t uuid_is_nil(struct uuid *, uint32_t *);
78 void uuid_create(uuid_t *, uint32_t *);
79 void uuid_create_nil(struct uuid *, uint32_t *);
80 void uuid_from_string(const char *, uuid_t *, uint32_t *);
81 void uuid_to_string(uuid_t *, char **, uint32_t *);
82 #endif
84 #ifdef HAVE_STDINT_H
85 #include <stdint.h>
86 #else
87 #include <inttypes.h>
88 #endif
90 #ifdef HAVE_QUEUE_H
91 #include <sys/queue.h>
92 #else
93 #include "compat/queue.h"
94 #endif
96 #ifdef HAVE_TREE_H
97 #include <sys/tree.h>
98 #else
99 #include "compat/tree.h"
100 #endif
102 #ifdef HAVE_UTIL_H
103 #include <util.h>
104 #endif
106 #ifdef HAVE_LIBUTIL_H
107 #include <libutil.h>
108 #endif
110 #ifdef HAVE_IMSG
111 #else
112 #include "compat/imsg.h"
113 #endif
115 #ifdef HAVE_LIBCRYPTO
116 #include <sha1.h>
117 #else
118 #include <sha.h>
120 #define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
121 #define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
123 #define SHA1_CTX SHA_CTX
124 #define SHA1Init SHA1_Init
125 #define SHA1Update SHA1_Update
126 #define SHA1Final SHA1_Final
127 #endif
129 #ifndef HAVE_ASPRINTF
130 /* asprintf.c */
131 int asprintf(char **, const char *, ...);
132 int vasprintf(char **, const char *, va_list);
133 #endif
135 #ifndef HAVE_EXPLICIT_BZERO
136 /* explicit_bzero.c */
137 void explicit_bzero(void *, size_t);
138 #endif
140 #ifndef HAVE_GETDTABLECOUNT
141 /* getdtablecount.c */
142 int getdtablecount(void);
143 #endif
145 #ifndef HAVE_CLOSEFROM
146 /* closefrom.c */
147 //void closefrom(int);
148 #define closefrom(fd) (closefrom(fd), 0)
149 #endif
151 #if defined (__FreeBSD__)
152 #define closefrom(fd) (closefrom(fd), 0)
153 #endif
155 #ifndef HAVE_STRSEP
156 /* strsep.c */
157 char *strsep(char **, const char *);
158 #endif
160 #ifndef HAVE_STRTONUM
161 /* strtonum.c */
162 long long strtonum(const char *, long long, long long, const char **);
163 #endif
165 #ifndef HAVE_STRLCPY
166 /* strlcpy.c */
167 size_t strlcpy(char *, const char *, size_t);
168 #endif
170 #ifndef HAVE_STRLCAT
171 /* strlcat.c */
172 size_t strlcat(char *, const char *, size_t);
173 #endif
175 #ifndef HAVE_STRNLEN
176 /* strnlen.c */
177 size_t strnlen(const char *, size_t);
178 #endif
180 #ifndef HAVE_STRNDUP
181 /* strndup.c */
182 char *strndup(const char *, size_t);
183 #endif
185 #ifndef HAVE_GETPROGNAME
186 /* getprogname.c */
187 const char *getprogname(void);
188 #endif
190 #ifndef HAVE_GETLINE
191 /* getline.c */
192 ssize_t getline(char **, size_t *, FILE *);
193 #endif
195 #ifndef HAVE_FREEZERO
196 /* freezero.c */
197 void freezero(void *, size_t);
198 #endif
200 #ifndef HAVE_GETDTABLECOUNT
201 /* getdtablecount.c */
202 int getdtablecount(void);
203 #endif
205 #ifndef HAVE_REALLOCARRAY
206 /* reallocarray.c */
207 void *reallocarray(void *, size_t, size_t);
208 #endif
210 #ifndef HAVE_RECALLOCARRAY
211 /* recallocarray.c */
212 void *recallocarray(void *, size_t, size_t, size_t);
213 #endif
215 #ifndef HAVE_FMT_SCALED
216 /* fmt_scaled.c */
217 int fmt_scaled(long long, char *);
218 int scan_scaled(char *, long long *);
219 #define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
221 #endif
223 #ifndef HAVE_LIBBSD
224 /* getopt.c */
225 extern int BSDopterr;
226 extern int BSDoptind;
227 extern int BSDoptopt;
228 extern int BSDoptreset;
229 extern char *BSDoptarg;
230 int BSDgetopt(int, char *const *, const char *);
231 #define getopt(ac, av, o) BSDgetopt(ac, av, o)
232 #define opterr BSDopterr
233 #define optind BSDoptind
234 #define optopt BSDoptopt
235 #define optreset BSDoptreset
236 #define optarg BSDoptarg
237 #endif
238 #endif
240 #ifndef HAVE_BSD_MERGESORT
241 /* mergesort.c */
242 int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
243 #endif