1 80189b3a 2022-08-13 op #if TEST___PROGNAME
5 80189b3a 2022-08-13 op extern char *__progname;
7 80189b3a 2022-08-13 op return !__progname;
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
14 80189b3a 2022-08-13 op #include <endian.h>
19 80189b3a 2022-08-13 op return !htole32(23);
21 80189b3a 2022-08-13 op #endif /* TEST_ENDIAN_H */
24 80189b3a 2022-08-13 op * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
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.
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.
39 80189b3a 2022-08-13 op #include <err.h>
40 80189b3a 2022-08-13 op #include <errno.h>
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 */
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>
61 80189b3a 2022-08-13 op return getdtablecount() == 0;
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>
70 80189b3a 2022-08-13 op const char * progname;
72 80189b3a 2022-08-13 op progname = getexecname();
73 80189b3a 2022-08-13 op return progname == NULL;
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>
82 80189b3a 2022-08-13 op const char * progname;
84 80189b3a 2022-08-13 op progname = getprogname();
85 80189b3a 2022-08-13 op return progname == NULL;
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>
94 80189b3a 2022-08-13 op struct event ev;
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);
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>
115 80189b3a 2022-08-13 op struct event ev;
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);
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>
129 80189b3a 2022-08-13 op int fds[2], c;
131 80189b3a 2022-08-13 op c = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
132 80189b3a 2022-08-13 op return c == -1;
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>
141 80189b3a 2022-08-13 op return !OSSwapHostToLittleInt32(23);
143 80189b3a 2022-08-13 op #endif /* TEST_OSBYTEORDER_H */
144 80189b3a 2022-08-13 op #if TEST_PATH_MAX
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.
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.
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.
166 80189b3a 2022-08-13 op #include <limits.h>
167 80189b3a 2022-08-13 op #include <stdio.h>
172 80189b3a 2022-08-13 op printf("PATH_MAX is defined to be %ld\n", (long)PATH_MAX);
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>
182 80189b3a 2022-08-13 op return !!pledge("stdio", NULL);
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>
193 80189b3a 2022-08-13 op return !program_invocation_short_name;
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>
204 80189b3a 2022-08-13 op return setresgid(-1, -1, -1) == -1;
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>
215 80189b3a 2022-08-13 op return setresuid(-1, -1, -1) == -1;
217 80189b3a 2022-08-13 op #endif /* TEST_SETRESUID */
218 80189b3a 2022-08-13 op #if TEST_SOCK_NONBLOCK
220 80189b3a 2022-08-13 op * Linux doesn't (always?) have this.
223 80189b3a 2022-08-13 op #include <sys/socket.h>
229 80189b3a 2022-08-13 op socketpair(AF_UNIX, SOCK_STREAM|SOCK_NONBLOCK, 0, fd);
232 80189b3a 2022-08-13 op #endif /* TEST_SOCK_NONBLOCK */
233 80189b3a 2022-08-13 op #if TEST_STATIC
237 80189b3a 2022-08-13 op return 0; /* not meant to do anything */
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>
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');
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>
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');
261 80189b3a 2022-08-13 op #endif /* TEST_STRLCPY */
262 80189b3a 2022-08-13 op #if TEST_STRTONUM
264 80189b3a 2022-08-13 op * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
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.
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.
278 80189b3a 2022-08-13 op #ifdef __NetBSD__
279 80189b3a 2022-08-13 op # define _OPENBSD_SOURCE
281 80189b3a 2022-08-13 op #include <stdlib.h>
286 80189b3a 2022-08-13 op const char *errstr;
288 80189b3a 2022-08-13 op if (strtonum("1", 0, 2, &errstr) != 1)
290 80189b3a 2022-08-13 op if (errstr != NULL)
292 80189b3a 2022-08-13 op if (strtonum("1x", 0, 2, &errstr) != 0)
294 80189b3a 2022-08-13 op if (errstr == NULL)
296 80189b3a 2022-08-13 op if (strtonum("2", 0, 1, &errstr) != 0)
298 80189b3a 2022-08-13 op if (errstr == NULL)
300 80189b3a 2022-08-13 op if (strtonum("0", 1, 2, &errstr) != 0)
302 80189b3a 2022-08-13 op if (errstr == NULL)
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>
313 80189b3a 2022-08-13 op return !LE_32(23);
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>
322 80189b3a 2022-08-13 op return !htole32(23);
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>
331 80189b3a 2022-08-13 op TAILQ_ENTRY(foo) entries;
334 80189b3a 2022-08-13 op TAILQ_HEAD(fooq, foo);
339 80189b3a 2022-08-13 op struct fooq foo_q, bar_q;
340 80189b3a 2022-08-13 op struct foo *p, *tmp;
343 80189b3a 2022-08-13 op TAILQ_INIT(&foo_q);
344 80189b3a 2022-08-13 op TAILQ_INIT(&bar_q);
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.
351 80189b3a 2022-08-13 op TAILQ_FOREACH_SAFE(p, &foo_q, entries, tmp)
352 80189b3a 2022-08-13 op p->bar = i++;
354 80189b3a 2022-08-13 op /* Test for newer macros as well. */
356 80189b3a 2022-08-13 op TAILQ_CONCAT(&foo_q, &bar_q, entries);
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>
368 80189b3a 2022-08-13 op return waitpid(WAIT_ANY, &st, WNOHANG) != -1;
370 80189b3a 2022-08-13 op #endif /* TEST_WAIT_ANY */