Blame


1 80189b3a 2022-08-13 op #if TEST___PROGNAME
2 80189b3a 2022-08-13 op int
3 80189b3a 2022-08-13 op main(void)
4 80189b3a 2022-08-13 op {
5 80189b3a 2022-08-13 op extern char *__progname;
6 80189b3a 2022-08-13 op
7 80189b3a 2022-08-13 op return !__progname;
8 80189b3a 2022-08-13 op }
9 80189b3a 2022-08-13 op #endif /* TEST___PROGNAME */
10 80189b3a 2022-08-13 op #if TEST_ENDIAN_H
11 80189b3a 2022-08-13 op #ifdef __linux__
12 80189b3a 2022-08-13 op # define _DEFAULT_SOURCE
13 80189b3a 2022-08-13 op #endif
14 80189b3a 2022-08-13 op #include <endian.h>
15 80189b3a 2022-08-13 op
16 80189b3a 2022-08-13 op int
17 80189b3a 2022-08-13 op main(void)
18 80189b3a 2022-08-13 op {
19 80189b3a 2022-08-13 op return !htole32(23);
20 80189b3a 2022-08-13 op }
21 80189b3a 2022-08-13 op #endif /* TEST_ENDIAN_H */
22 80189b3a 2022-08-13 op #if TEST_ERR
23 80189b3a 2022-08-13 op /*
24 80189b3a 2022-08-13 op * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
25 80189b3a 2022-08-13 op *
26 80189b3a 2022-08-13 op * Permission to use, copy, modify, and distribute this software for any
27 80189b3a 2022-08-13 op * purpose with or without fee is hereby granted, provided that the above
28 80189b3a 2022-08-13 op * copyright notice and this permission notice appear in all copies.
29 80189b3a 2022-08-13 op *
30 80189b3a 2022-08-13 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
31 80189b3a 2022-08-13 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
32 80189b3a 2022-08-13 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
33 80189b3a 2022-08-13 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
34 80189b3a 2022-08-13 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
35 80189b3a 2022-08-13 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
36 80189b3a 2022-08-13 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
37 80189b3a 2022-08-13 op */
38 80189b3a 2022-08-13 op
39 80189b3a 2022-08-13 op #include <err.h>
40 80189b3a 2022-08-13 op #include <errno.h>
41 80189b3a 2022-08-13 op
42 80189b3a 2022-08-13 op int
43 80189b3a 2022-08-13 op main(void)
44 80189b3a 2022-08-13 op {
45 80189b3a 2022-08-13 op warnx("%d. warnx", 1);
46 80189b3a 2022-08-13 op warnc(ENOENT, "%d. warn", ENOENT);
47 80189b3a 2022-08-13 op warn("%d. warn", 2);
48 80189b3a 2022-08-13 op err(0, "%d. err", 3);
49 80189b3a 2022-08-13 op errx(0, "%d. err", 3);
50 80189b3a 2022-08-13 op errc(0, ENOENT, "%d. err", 3);
51 80189b3a 2022-08-13 op /* NOTREACHED */
52 80189b3a 2022-08-13 op return 1;
53 80189b3a 2022-08-13 op }
54 80189b3a 2022-08-13 op #endif /* TEST_ERR */
55 80189b3a 2022-08-13 op #if TEST_GETDTABLECOUNT
56 80189b3a 2022-08-13 op #include <unistd.h>
57 80189b3a 2022-08-13 op
58 80189b3a 2022-08-13 op int
59 80189b3a 2022-08-13 op main(void)
60 80189b3a 2022-08-13 op {
61 80189b3a 2022-08-13 op return getdtablecount() == 0;
62 80189b3a 2022-08-13 op }
63 80189b3a 2022-08-13 op #endif /* TEST_GETDTABLECOUNT */
64 80189b3a 2022-08-13 op #if TEST_GETEXECNAME
65 80189b3a 2022-08-13 op #include <stdlib.h>
66 80189b3a 2022-08-13 op
67 80189b3a 2022-08-13 op int
68 80189b3a 2022-08-13 op main(void)
69 80189b3a 2022-08-13 op {
70 80189b3a 2022-08-13 op const char * progname;
71 80189b3a 2022-08-13 op
72 80189b3a 2022-08-13 op progname = getexecname();
73 80189b3a 2022-08-13 op return progname == NULL;
74 80189b3a 2022-08-13 op }
75 80189b3a 2022-08-13 op #endif /* TEST_GETEXECNAME */
76 80189b3a 2022-08-13 op #if TEST_GETPROGNAME
77 80189b3a 2022-08-13 op #include <stdlib.h>
78 80189b3a 2022-08-13 op
79 80189b3a 2022-08-13 op int
80 80189b3a 2022-08-13 op main(void)
81 80189b3a 2022-08-13 op {
82 80189b3a 2022-08-13 op const char * progname;
83 80189b3a 2022-08-13 op
84 80189b3a 2022-08-13 op progname = getprogname();
85 80189b3a 2022-08-13 op return progname == NULL;
86 80189b3a 2022-08-13 op }
87 80189b3a 2022-08-13 op #endif /* TEST_GETPROGNAME */
88 80189b3a 2022-08-13 op #if TEST_LIBEVENT
89 80189b3a 2022-08-13 op #include <event.h>
90 80189b3a 2022-08-13 op
91 80189b3a 2022-08-13 op int
92 80189b3a 2022-08-13 op main(void)
93 80189b3a 2022-08-13 op {
94 80189b3a 2022-08-13 op struct event ev;
95 80189b3a 2022-08-13 op
96 80189b3a 2022-08-13 op event_set(&ev, 0, EV_READ, NULL, NULL);
97 80189b3a 2022-08-13 op event_add(&ev, NULL);
98 80189b3a 2022-08-13 op event_del(&ev);
99 80189b3a 2022-08-13 op return 0;
100 80189b3a 2022-08-13 op }
101 80189b3a 2022-08-13 op #endif /* TEST_LIBEVENT */
102 80189b3a 2022-08-13 op #if TEST_LIBEVENT2
103 80189b3a 2022-08-13 op #include <event2/event.h>
104 80189b3a 2022-08-13 op #include <event2/event_compat.h>
105 80189b3a 2022-08-13 op #include <event2/event_struct.h>
106 80189b3a 2022-08-13 op #include <event2/buffer.h>
107 80189b3a 2022-08-13 op #include <event2/buffer_compat.h>
108 80189b3a 2022-08-13 op #include <event2/bufferevent.h>
109 80189b3a 2022-08-13 op #include <event2/bufferevent_struct.h>
110 80189b3a 2022-08-13 op #include <event2/bufferevent_compat.h>
111 80189b3a 2022-08-13 op
112 80189b3a 2022-08-13 op int
113 80189b3a 2022-08-13 op main(void)
114 80189b3a 2022-08-13 op {
115 80189b3a 2022-08-13 op struct event ev;
116 80189b3a 2022-08-13 op
117 80189b3a 2022-08-13 op event_set(&ev, 0, EV_READ, NULL, NULL);
118 80189b3a 2022-08-13 op event_add(&ev, NULL);
119 80189b3a 2022-08-13 op event_del(&ev);
120 80189b3a 2022-08-13 op return 0;
121 80189b3a 2022-08-13 op }
122 80189b3a 2022-08-13 op #endif /* TEST_LIBEVENT2 */
123 80189b3a 2022-08-13 op #if TEST_LIB_SOCKET
124 80189b3a 2022-08-13 op #include <sys/socket.h>
125 80189b3a 2022-08-13 op
126 80189b3a 2022-08-13 op int
127 80189b3a 2022-08-13 op main(void)
128 80189b3a 2022-08-13 op {
129 80189b3a 2022-08-13 op int fds[2], c;
130 80189b3a 2022-08-13 op
131 80189b3a 2022-08-13 op c = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
132 80189b3a 2022-08-13 op return c == -1;
133 80189b3a 2022-08-13 op }
134 80189b3a 2022-08-13 op #endif /* TEST_LIB_SOCKET */
135 80189b3a 2022-08-13 op #if TEST_OSBYTEORDER_H
136 80189b3a 2022-08-13 op #include <libkern/OSByteOrder.h>
137 80189b3a 2022-08-13 op
138 80189b3a 2022-08-13 op int
139 80189b3a 2022-08-13 op main(void)
140 80189b3a 2022-08-13 op {
141 80189b3a 2022-08-13 op return !OSSwapHostToLittleInt32(23);
142 80189b3a 2022-08-13 op }
143 80189b3a 2022-08-13 op #endif /* TEST_OSBYTEORDER_H */
144 80189b3a 2022-08-13 op #if TEST_PATH_MAX
145 80189b3a 2022-08-13 op /*
146 80189b3a 2022-08-13 op * POSIX allows PATH_MAX to not be defined, see
147 80189b3a 2022-08-13 op * http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html;
148 80189b3a 2022-08-13 op * the GNU Hurd is an example of a system not having it.
149 80189b3a 2022-08-13 op *
150 80189b3a 2022-08-13 op * Arguably, it would be better to test sysconf(_SC_PATH_MAX),
151 80189b3a 2022-08-13 op * but since the individual *.c files include "config.h" before
152 80189b3a 2022-08-13 op * <limits.h>, overriding an excessive value of PATH_MAX from
153 80189b3a 2022-08-13 op * "config.h" is impossible anyway, so for now, the simplest
154 80189b3a 2022-08-13 op * fix is to provide a value only on systems not having any.
155 80189b3a 2022-08-13 op * So far, we encountered no system defining PATH_MAX to an
156 80189b3a 2022-08-13 op * impractically large value, even though POSIX explicitly
157 80189b3a 2022-08-13 op * allows that.
158 80189b3a 2022-08-13 op *
159 80189b3a 2022-08-13 op * The real fix would be to replace all static buffers of size
160 80189b3a 2022-08-13 op * PATH_MAX by dynamically allocated buffers. But that is
161 80189b3a 2022-08-13 op * somewhat intrusive because it touches several files and
162 80189b3a 2022-08-13 op * because it requires changing struct mlink in mandocdb.c.
163 80189b3a 2022-08-13 op * So i'm postponing that for now.
164 80189b3a 2022-08-13 op */
165 80189b3a 2022-08-13 op
166 80189b3a 2022-08-13 op #include <limits.h>
167 80189b3a 2022-08-13 op #include <stdio.h>
168 80189b3a 2022-08-13 op
169 80189b3a 2022-08-13 op int
170 80189b3a 2022-08-13 op main(void)
171 80189b3a 2022-08-13 op {
172 80189b3a 2022-08-13 op printf("PATH_MAX is defined to be %ld\n", (long)PATH_MAX);
173 80189b3a 2022-08-13 op return 0;
174 80189b3a 2022-08-13 op }
175 80189b3a 2022-08-13 op #endif /* TEST_PATH_MAX */
176 80189b3a 2022-08-13 op #if TEST_PLEDGE
177 80189b3a 2022-08-13 op #include <unistd.h>
178 80189b3a 2022-08-13 op
179 80189b3a 2022-08-13 op int
180 80189b3a 2022-08-13 op main(void)
181 80189b3a 2022-08-13 op {
182 80189b3a 2022-08-13 op return !!pledge("stdio", NULL);
183 80189b3a 2022-08-13 op }
184 80189b3a 2022-08-13 op #endif /* TEST_PLEDGE */
185 80189b3a 2022-08-13 op #if TEST_PROGRAM_INVOCATION_SHORT_NAME
186 80189b3a 2022-08-13 op #define _GNU_SOURCE /* See feature_test_macros(7) */
187 80189b3a 2022-08-13 op #include <errno.h>
188 80189b3a 2022-08-13 op
189 80189b3a 2022-08-13 op int
190 80189b3a 2022-08-13 op main(void)
191 80189b3a 2022-08-13 op {
192 80189b3a 2022-08-13 op
193 80189b3a 2022-08-13 op return !program_invocation_short_name;
194 80189b3a 2022-08-13 op }
195 80189b3a 2022-08-13 op #endif /* TEST_PROGRAM_INVOCATION_SHORT_NAME */
196 80189b3a 2022-08-13 op #if TEST_SETRESGID
197 80189b3a 2022-08-13 op #define _GNU_SOURCE /* linux */
198 80189b3a 2022-08-13 op #include <sys/types.h>
199 80189b3a 2022-08-13 op #include <unistd.h>
200 80189b3a 2022-08-13 op
201 80189b3a 2022-08-13 op int
202 80189b3a 2022-08-13 op main(void)
203 80189b3a 2022-08-13 op {
204 80189b3a 2022-08-13 op return setresgid(-1, -1, -1) == -1;
205 80189b3a 2022-08-13 op }
206 80189b3a 2022-08-13 op #endif /* TEST_SETRESGID */
207 80189b3a 2022-08-13 op #if TEST_SETRESUID
208 80189b3a 2022-08-13 op #define _GNU_SOURCE /* linux */
209 80189b3a 2022-08-13 op #include <sys/types.h>
210 80189b3a 2022-08-13 op #include <unistd.h>
211 80189b3a 2022-08-13 op
212 80189b3a 2022-08-13 op int
213 80189b3a 2022-08-13 op main(void)
214 80189b3a 2022-08-13 op {
215 80189b3a 2022-08-13 op return setresuid(-1, -1, -1) == -1;
216 80189b3a 2022-08-13 op }
217 80189b3a 2022-08-13 op #endif /* TEST_SETRESUID */
218 80189b3a 2022-08-13 op #if TEST_SOCK_NONBLOCK
219 80189b3a 2022-08-13 op /*
220 80189b3a 2022-08-13 op * Linux doesn't (always?) have this.
221 80189b3a 2022-08-13 op */
222 80189b3a 2022-08-13 op
223 80189b3a 2022-08-13 op #include <sys/socket.h>
224 80189b3a 2022-08-13 op
225 80189b3a 2022-08-13 op int
226 80189b3a 2022-08-13 op main(void)
227 80189b3a 2022-08-13 op {
228 80189b3a 2022-08-13 op int fd[2];
229 80189b3a 2022-08-13 op socketpair(AF_UNIX, SOCK_STREAM|SOCK_NONBLOCK, 0, fd);
230 80189b3a 2022-08-13 op return 0;
231 80189b3a 2022-08-13 op }
232 80189b3a 2022-08-13 op #endif /* TEST_SOCK_NONBLOCK */
233 80189b3a 2022-08-13 op #if TEST_STATIC
234 80189b3a 2022-08-13 op int
235 80189b3a 2022-08-13 op main(void)
236 80189b3a 2022-08-13 op {
237 80189b3a 2022-08-13 op return 0; /* not meant to do anything */
238 80189b3a 2022-08-13 op }
239 80189b3a 2022-08-13 op #endif /* TEST_STATIC */
240 80189b3a 2022-08-13 op #if TEST_STRLCAT
241 80189b3a 2022-08-13 op #include <string.h>
242 80189b3a 2022-08-13 op
243 80189b3a 2022-08-13 op int
244 80189b3a 2022-08-13 op main(void)
245 80189b3a 2022-08-13 op {
246 80189b3a 2022-08-13 op char buf[3] = "a";
247 80189b3a 2022-08-13 op return ! (strlcat(buf, "b", sizeof(buf)) == 2 &&
248 80189b3a 2022-08-13 op buf[0] == 'a' && buf[1] == 'b' && buf[2] == '\0');
249 80189b3a 2022-08-13 op }
250 80189b3a 2022-08-13 op #endif /* TEST_STRLCAT */
251 80189b3a 2022-08-13 op #if TEST_STRLCPY
252 80189b3a 2022-08-13 op #include <string.h>
253 80189b3a 2022-08-13 op
254 80189b3a 2022-08-13 op int
255 80189b3a 2022-08-13 op main(void)
256 80189b3a 2022-08-13 op {
257 80189b3a 2022-08-13 op char buf[2] = "";
258 80189b3a 2022-08-13 op return ! (strlcpy(buf, "a", sizeof(buf)) == 1 &&
259 80189b3a 2022-08-13 op buf[0] == 'a' && buf[1] == '\0');
260 80189b3a 2022-08-13 op }
261 80189b3a 2022-08-13 op #endif /* TEST_STRLCPY */
262 80189b3a 2022-08-13 op #if TEST_STRTONUM
263 80189b3a 2022-08-13 op /*
264 80189b3a 2022-08-13 op * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
265 80189b3a 2022-08-13 op *
266 80189b3a 2022-08-13 op * Permission to use, copy, modify, and distribute this software for any
267 80189b3a 2022-08-13 op * purpose with or without fee is hereby granted, provided that the above
268 80189b3a 2022-08-13 op * copyright notice and this permission notice appear in all copies.
269 80189b3a 2022-08-13 op *
270 80189b3a 2022-08-13 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
271 80189b3a 2022-08-13 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
272 80189b3a 2022-08-13 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
273 80189b3a 2022-08-13 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
274 80189b3a 2022-08-13 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
275 80189b3a 2022-08-13 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
276 80189b3a 2022-08-13 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
277 80189b3a 2022-08-13 op */
278 80189b3a 2022-08-13 op #ifdef __NetBSD__
279 80189b3a 2022-08-13 op # define _OPENBSD_SOURCE
280 80189b3a 2022-08-13 op #endif
281 80189b3a 2022-08-13 op #include <stdlib.h>
282 80189b3a 2022-08-13 op
283 80189b3a 2022-08-13 op int
284 80189b3a 2022-08-13 op main(void)
285 80189b3a 2022-08-13 op {
286 80189b3a 2022-08-13 op const char *errstr;
287 80189b3a 2022-08-13 op
288 80189b3a 2022-08-13 op if (strtonum("1", 0, 2, &errstr) != 1)
289 80189b3a 2022-08-13 op return 1;
290 80189b3a 2022-08-13 op if (errstr != NULL)
291 80189b3a 2022-08-13 op return 2;
292 80189b3a 2022-08-13 op if (strtonum("1x", 0, 2, &errstr) != 0)
293 80189b3a 2022-08-13 op return 3;
294 80189b3a 2022-08-13 op if (errstr == NULL)
295 80189b3a 2022-08-13 op return 4;
296 80189b3a 2022-08-13 op if (strtonum("2", 0, 1, &errstr) != 0)
297 80189b3a 2022-08-13 op return 5;
298 80189b3a 2022-08-13 op if (errstr == NULL)
299 80189b3a 2022-08-13 op return 6;
300 80189b3a 2022-08-13 op if (strtonum("0", 1, 2, &errstr) != 0)
301 80189b3a 2022-08-13 op return 7;
302 80189b3a 2022-08-13 op if (errstr == NULL)
303 80189b3a 2022-08-13 op return 8;
304 80189b3a 2022-08-13 op return 0;
305 80189b3a 2022-08-13 op }
306 80189b3a 2022-08-13 op #endif /* TEST_STRTONUM */
307 80189b3a 2022-08-13 op #if TEST_SYS_BYTEORDER_H
308 80189b3a 2022-08-13 op #include <sys/byteorder.h>
309 80189b3a 2022-08-13 op
310 80189b3a 2022-08-13 op int
311 80189b3a 2022-08-13 op main(void)
312 80189b3a 2022-08-13 op {
313 80189b3a 2022-08-13 op return !LE_32(23);
314 80189b3a 2022-08-13 op }
315 80189b3a 2022-08-13 op #endif /* TEST_SYS_BYTEORDER_H */
316 80189b3a 2022-08-13 op #if TEST_SYS_ENDIAN_H
317 80189b3a 2022-08-13 op #include <sys/endian.h>
318 80189b3a 2022-08-13 op
319 80189b3a 2022-08-13 op int
320 80189b3a 2022-08-13 op main(void)
321 80189b3a 2022-08-13 op {
322 80189b3a 2022-08-13 op return !htole32(23);
323 80189b3a 2022-08-13 op }
324 80189b3a 2022-08-13 op #endif /* TEST_SYS_ENDIAN_H */
325 80189b3a 2022-08-13 op #if TEST_SYS_QUEUE
326 80189b3a 2022-08-13 op #include <sys/queue.h>
327 80189b3a 2022-08-13 op #include <stddef.h>
328 80189b3a 2022-08-13 op
329 80189b3a 2022-08-13 op struct foo {
330 80189b3a 2022-08-13 op int bar;
331 80189b3a 2022-08-13 op TAILQ_ENTRY(foo) entries;
332 80189b3a 2022-08-13 op };
333 80189b3a 2022-08-13 op
334 80189b3a 2022-08-13 op TAILQ_HEAD(fooq, foo);
335 80189b3a 2022-08-13 op
336 80189b3a 2022-08-13 op int
337 80189b3a 2022-08-13 op main(void)
338 80189b3a 2022-08-13 op {
339 80189b3a 2022-08-13 op struct fooq foo_q, bar_q;
340 80189b3a 2022-08-13 op struct foo *p, *tmp;
341 80189b3a 2022-08-13 op int i = 0;
342 80189b3a 2022-08-13 op
343 80189b3a 2022-08-13 op TAILQ_INIT(&foo_q);
344 80189b3a 2022-08-13 op TAILQ_INIT(&bar_q);
345 80189b3a 2022-08-13 op
346 80189b3a 2022-08-13 op /*
347 80189b3a 2022-08-13 op * Use TAILQ_FOREACH_SAFE because some systems (e.g., Linux)
348 80189b3a 2022-08-13 op * have TAILQ_FOREACH but not the safe variant.
349 80189b3a 2022-08-13 op */
350 80189b3a 2022-08-13 op
351 80189b3a 2022-08-13 op TAILQ_FOREACH_SAFE(p, &foo_q, entries, tmp)
352 80189b3a 2022-08-13 op p->bar = i++;
353 80189b3a 2022-08-13 op
354 80189b3a 2022-08-13 op /* Test for newer macros as well. */
355 80189b3a 2022-08-13 op
356 80189b3a 2022-08-13 op TAILQ_CONCAT(&foo_q, &bar_q, entries);
357 80189b3a 2022-08-13 op return 0;
358 80189b3a 2022-08-13 op }
359 80189b3a 2022-08-13 op #endif /* TEST_SYS_QUEUE */
360 80189b3a 2022-08-13 op #if TEST_WAIT_ANY
361 80189b3a 2022-08-13 op #include <sys/wait.h>
362 80189b3a 2022-08-13 op
363 80189b3a 2022-08-13 op int
364 80189b3a 2022-08-13 op main(void)
365 80189b3a 2022-08-13 op {
366 80189b3a 2022-08-13 op int st;
367 80189b3a 2022-08-13 op
368 80189b3a 2022-08-13 op return waitpid(WAIT_ANY, &st, WNOHANG) != -1;
369 80189b3a 2022-08-13 op }
370 80189b3a 2022-08-13 op #endif /* TEST_WAIT_ANY */