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 #ifndef INFTIM
47 #define INFTIM -1
48 #endif
50 #ifndef HAVE_BSD_UUID
51 #include <uuid/uuid.h>
52 #define uuid_s_ok 0
53 #define uuid_s_bad_version 1
54 #define uuid_s_invalid_string_uuid 2
55 #define uuid_s_no_memory 3
57 /* Length of a node address (an IEEE 802 address). */
58 #define _UUID_NODE_LEN 6
60 struct uuid {
61 uint32_t time_low;
62 uint16_t time_mid;
63 uint16_t time_hi_and_version;
64 uint8_t clock_seq_hi_and_reserved;
65 uint8_t clock_seq_low;
66 uint8_t node[_UUID_NODE_LEN];
67 };
69 int32_t uuid_equal(struct uuid *, struct uuid *, uint32_t *);
70 int32_t uuid_is_nil(struct uuid *, uint32_t *);
71 void uuid_create(uuid_t *, uint32_t *);
72 void uuid_create_nil(struct uuid *, uint32_t *);
73 void uuid_from_string(const char *, uuid_t *, uint32_t *);
74 void uuid_to_string(uuid_t *, char **, uint32_t *);
75 #endif
77 #ifdef HAVE_STDINT_H
78 #include <stdint.h>
79 #else
80 #include <inttypes.h>
81 #endif
83 #ifdef HAVE_QUEUE_H
84 #include <sys/queue.h>
85 #else
86 #include "compat/queue.h"
87 #endif
89 #ifdef HAVE_TREE_H
90 #include <sys/tree.h>
91 #else
92 #include "compat/tree.h"
93 #endif
95 #ifdef HAVE_UTIL_H
96 #include <util.h>
97 #endif
99 #ifdef HAVE_LIBUTIL_H
100 #include <libutil.h>
101 #endif
103 #ifdef HAVE_IMSG
104 #else
105 #include "compat/imsg.h"
106 #endif
108 #ifdef HAVE_LIBCRYPTO
109 #include <sha1.h>
110 #else
111 #include <sha.h>
113 #define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
114 #define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
116 #define SHA1_CTX SHA_CTX
117 #define SHA1Init SHA1_Init
118 #define SHA1Update SHA1_Update
119 #define SHA1Final SHA1_Final
120 #endif
122 #ifndef HAVE_ASPRINTF
123 /* asprintf.c */
124 int asprintf(char **, const char *, ...);
125 int vasprintf(char **, const char *, va_list);
126 #endif
128 #ifndef HAVE_EXPLICIT_BZERO
129 /* explicit_bzero.c */
130 void explicit_bzero(void *, size_t);
131 #endif
133 #ifndef HAVE_GETDTABLECOUNT
134 /* getdtablecount.c */
135 int getdtablecount(void);
136 #endif
138 #ifndef HAVE_CLOSEFROM
139 /* closefrom.c */
140 //void closefrom(int);
141 #define closefrom(fd) (closefrom(fd), 0)
142 #endif
144 #if defined (__FreeBSD__)
145 #define closefrom(fd) (closefrom(fd), 0)
146 #endif
148 #ifndef HAVE_STRSEP
149 /* strsep.c */
150 char *strsep(char **, const char *);
151 #endif
153 #ifndef HAVE_STRTONUM
154 /* strtonum.c */
155 long long strtonum(const char *, long long, long long, const char **);
156 #endif
158 #ifndef HAVE_STRLCPY
159 /* strlcpy.c */
160 size_t strlcpy(char *, const char *, size_t);
161 #endif
163 #ifndef HAVE_STRLCAT
164 /* strlcat.c */
165 size_t strlcat(char *, const char *, size_t);
166 #endif
168 #ifndef HAVE_STRNLEN
169 /* strnlen.c */
170 size_t strnlen(const char *, size_t);
171 #endif
173 #ifndef HAVE_STRNDUP
174 /* strndup.c */
175 char *strndup(const char *, size_t);
176 #endif
178 #ifndef HAVE_GETPROGNAME
179 /* getprogname.c */
180 const char *getprogname(void);
181 #endif
183 #ifndef HAVE_GETLINE
184 /* getline.c */
185 ssize_t getline(char **, size_t *, FILE *);
186 #endif
188 #ifndef HAVE_FREEZERO
189 /* freezero.c */
190 void freezero(void *, size_t);
191 #endif
193 #ifndef HAVE_GETDTABLECOUNT
194 /* getdtablecount.c */
195 int getdtablecount(void);
196 #endif
198 #ifndef HAVE_REALLOCARRAY
199 /* reallocarray.c */
200 void *reallocarray(void *, size_t, size_t);
201 #endif
203 #ifndef HAVE_RECALLOCARRAY
204 /* recallocarray.c */
205 void *recallocarray(void *, size_t, size_t, size_t);
206 #endif
208 #ifndef HAVE_FMT_SCALED
209 /* fmt_scaled.c */
210 int fmt_scaled(long long, char *);
211 int scan_scaled(char *, long long *);
212 #define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
214 #endif
216 #ifndef HAVE_LIBBSD
217 /* getopt.c */
218 extern int BSDopterr;
219 extern int BSDoptind;
220 extern int BSDoptopt;
221 extern int BSDoptreset;
222 extern char *BSDoptarg;
223 int BSDgetopt(int, char *const *, const char *);
224 #define getopt(ac, av, o) BSDgetopt(ac, av, o)
225 #define opterr BSDopterr
226 #define optind BSDoptind
227 #define optopt BSDoptopt
228 #define optreset BSDoptreset
229 #define optarg BSDoptarg
230 #endif
231 #endif
233 #ifndef HAVE_BSD_MERGESORT
234 /* mergesort.c */
235 int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
236 #endif