portable: initial Linux compilation
[got-portable.git] / include / got_compat.h
blob6270fd4e8165f8236d032b97398fed86ef03d723
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>
8 #include <fnmatch.h>
9 #include <limits.h>
10 #include <stdio.h>
11 #include <stdint.h>
14 #include <termios.h>
15 #include <wchar.h>
18 /* For flock. */
19 #ifndef O_EXLOCK
20 #define O_EXLOCK 0
21 #endif
23 #ifndef HAVE_FLOCK
24 #define LOCK_SH 0
25 #define LOCK_EX 0
26 #define LOCK_NB 0
27 #define flock(fd, op) (0)
28 #else
29 #include <sys/file.h>
30 #endif
32 #ifndef __dead
33 #define __dead __attribute__ ((__noreturn__))
34 #endif
36 #ifndef __OpenBSD__
37 #define pledge(s, p) (0)
38 #define unveil(s, p) (0)
39 #endif
41 #ifndef INFTIM
42 #define INFTIM -1
43 #endif
45 #ifndef HAVE_BSD_UUID
46 #include <uuid/uuid.h>
47 #define uuid_s_ok 0
48 #define uuid_s_bad_version 1
49 #define uuid_s_invalid_string_uuid 2
50 #define uuid_s_no_memory 3
52 /* Length of a node address (an IEEE 802 address). */
53 #define _UUID_NODE_LEN 6
55 struct uuid {
56 uint32_t time_low;
57 uint16_t time_mid;
58 uint16_t time_hi_and_version;
59 uint8_t clock_seq_hi_and_reserved;
60 uint8_t clock_seq_low;
61 uint8_t node[_UUID_NODE_LEN];
64 int32_t uuid_equal(struct uuid *, struct uuid *, uint32_t *);
65 int32_t uuid_is_nil(struct uuid *, uint32_t *);
66 void uuid_create(uuid_t *, uint32_t *);
67 void uuid_create_nil(struct uuid *, uint32_t *);
68 void uuid_from_string(const char *, uuid_t *, uint32_t *);
69 void uuid_to_string(uuid_t *, char **, uint32_t *);
70 #endif
72 #ifdef HAVE_STDINT_H
73 #include <stdint.h>
74 #else
75 #include <inttypes.h>
76 #endif
78 #ifdef HAVE_QUEUE_H
79 #include <sys/queue.h>
80 #else
81 #include "compat/queue.h"
82 #endif
84 #ifdef HAVE_TREE_H
85 #include <sys/tree.h>
86 #else
87 #include "compat/tree.h"
88 #endif
90 #ifdef HAVE_UTIL_H
91 #include <util.h>
92 #endif
94 #ifdef HAVE_LIBUTIL_H
95 #include <libutil.h>
96 #endif
98 #ifdef HAVE_IMSG
99 #else
100 #include "compat/imsg.h"
101 #endif
103 #ifndef HAVE_ASPRINTF
104 /* asprintf.c */
105 int asprintf(char **, const char *, ...);
106 int vasprintf(char **, const char *, va_list);
107 #endif
109 #ifndef HAVE_EXPLICIT_BZERO
110 /* explicit_bzero.c */
111 void explicit_bzero(void *, size_t);
112 #endif
114 #ifndef HAVE_GETDTABLECOUNT
115 /* getdtablecount.c */
116 int getdtablecount(void);
117 #endif
119 #ifndef HAVE_CLOSEFROM
120 /* closefrom.c */
121 //void closefrom(int);
122 #define closefrom(fd) (closefrom(fd), 0)
123 #endif
125 #ifndef HAVE_STRSEP
126 /* strsep.c */
127 char *strsep(char **, const char *);
128 #endif
130 #ifndef HAVE_STRTONUM
131 /* strtonum.c */
132 long long strtonum(const char *, long long, long long, const char **);
133 #endif
135 #ifndef HAVE_STRLCPY
136 /* strlcpy.c */
137 size_t strlcpy(char *, const char *, size_t);
138 #endif
140 #ifndef HAVE_STRLCAT
141 /* strlcat.c */
142 size_t strlcat(char *, const char *, size_t);
143 #endif
145 #ifndef HAVE_STRNLEN
146 /* strnlen.c */
147 size_t strnlen(const char *, size_t);
148 #endif
150 #ifndef HAVE_STRNDUP
151 /* strndup.c */
152 char *strndup(const char *, size_t);
153 #endif
155 #ifndef HAVE_GETPROGNAME
156 /* getprogname.c */
157 const char *getprogname(void);
158 #endif
160 #ifndef HAVE_GETLINE
161 /* getline.c */
162 ssize_t getline(char **, size_t *, FILE *);
163 #endif
165 #ifndef HAVE_FREEZERO
166 /* freezero.c */
167 void freezero(void *, size_t);
168 #endif
170 #ifndef HAVE_GETDTABLECOUNT
171 /* getdtablecount.c */
172 int getdtablecount(void);
173 #endif
175 #ifndef HAVE_REALLOCARRAY
176 /* reallocarray.c */
177 void *reallocarray(void *, size_t, size_t);
178 #endif
180 #ifndef HAVE_RECALLOCARRAY
181 /* recallocarray.c */
182 void *recallocarray(void *, size_t, size_t, size_t);
183 #endif
185 #ifndef HAVE_FMT_SCALED
186 /* fmt_scaled.c */
187 int fmt_scaled(long long, char *);
188 int scan_scaled(char *, long long *);
189 #define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
191 #endif
193 #ifndef HAVE_LIBBSD
194 /* getopt.c */
195 extern int BSDopterr;
196 extern int BSDoptind;
197 extern int BSDoptopt;
198 extern int BSDoptreset;
199 extern char *BSDoptarg;
200 int BSDgetopt(int, char *const *, const char *);
201 #define getopt(ac, av, o) BSDgetopt(ac, av, o)
202 #define opterr BSDopterr
203 #define optind BSDoptind
204 #define optopt BSDoptopt
205 #define optreset BSDoptreset
206 #define optarg BSDoptarg
207 #endif
208 #endif
210 #ifndef HAVE_BSD_MERGESORT
211 /* mergesort.c */
212 int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
213 #endif