5 extern char *__progname;
9 #endif /* TEST___PROGNAME */
12 # define _DEFAULT_SOURCE
21 #endif /* TEST_ENDIAN_H */
24 * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
26 * Permission to use, copy, modify, and distribute this software for any
27 * purpose with or without fee is hereby granted, provided that the above
28 * copyright notice and this permission notice appear in all copies.
30 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
31 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
32 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
33 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
34 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
35 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
36 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
45 warnx("%d. warnx", 1);
46 warnc(ENOENT, "%d. warn", ENOENT);
49 errx(0, "%d. err", 3);
50 errc(0, ENOENT, "%d. err", 3);
55 #if TEST_GETDTABLECOUNT
61 return getdtablecount() == 0;
63 #endif /* TEST_GETDTABLECOUNT */
70 const char * progname;
72 progname = getexecname();
73 return progname == NULL;
75 #endif /* TEST_GETEXECNAME */
82 const char * progname;
84 progname = getprogname();
85 return progname == NULL;
87 #endif /* TEST_GETPROGNAME */
96 event_set(&ev, 0, EV_READ, NULL, NULL);
101 #endif /* TEST_LIBEVENT */
103 #include <event2/event.h>
104 #include <event2/event_compat.h>
105 #include <event2/event_struct.h>
106 #include <event2/buffer.h>
107 #include <event2/buffer_compat.h>
108 #include <event2/bufferevent.h>
109 #include <event2/bufferevent_struct.h>
110 #include <event2/bufferevent_compat.h>
117 event_set(&ev, 0, EV_READ, NULL, NULL);
118 event_add(&ev, NULL);
122 #endif /* TEST_LIBEVENT2 */
124 #include <sys/socket.h>
131 c = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
134 #endif /* TEST_LIB_SOCKET */
135 #if TEST_OSBYTEORDER_H
136 #include <libkern/OSByteOrder.h>
141 return !OSSwapHostToLittleInt32(23);
143 #endif /* TEST_OSBYTEORDER_H */
146 * POSIX allows PATH_MAX to not be defined, see
147 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html;
148 * the GNU Hurd is an example of a system not having it.
150 * Arguably, it would be better to test sysconf(_SC_PATH_MAX),
151 * but since the individual *.c files include "config.h" before
152 * <limits.h>, overriding an excessive value of PATH_MAX from
153 * "config.h" is impossible anyway, so for now, the simplest
154 * fix is to provide a value only on systems not having any.
155 * So far, we encountered no system defining PATH_MAX to an
156 * impractically large value, even though POSIX explicitly
159 * The real fix would be to replace all static buffers of size
160 * PATH_MAX by dynamically allocated buffers. But that is
161 * somewhat intrusive because it touches several files and
162 * because it requires changing struct mlink in mandocdb.c.
163 * So i'm postponing that for now.
172 printf("PATH_MAX is defined to be %ld\n", (long)PATH_MAX);
175 #endif /* TEST_PATH_MAX */
182 return !!pledge("stdio", NULL);
184 #endif /* TEST_PLEDGE */
185 #if TEST_PROGRAM_INVOCATION_SHORT_NAME
186 #define _GNU_SOURCE /* See feature_test_macros(7) */
193 return !program_invocation_short_name;
195 #endif /* TEST_PROGRAM_INVOCATION_SHORT_NAME */
197 #define _GNU_SOURCE /* linux */
198 #include <sys/types.h>
204 return setresgid(-1, -1, -1) == -1;
206 #endif /* TEST_SETRESGID */
208 #define _GNU_SOURCE /* linux */
209 #include <sys/types.h>
215 return setresuid(-1, -1, -1) == -1;
217 #endif /* TEST_SETRESUID */
218 #if TEST_SOCK_NONBLOCK
220 * Linux doesn't (always?) have this.
223 #include <sys/socket.h>
229 socketpair(AF_UNIX, SOCK_STREAM|SOCK_NONBLOCK, 0, fd);
232 #endif /* TEST_SOCK_NONBLOCK */
237 return 0; /* not meant to do anything */
239 #endif /* TEST_STATIC */
247 return ! (strlcat(buf, "b", sizeof(buf)) == 2 &&
248 buf[0] == 'a' && buf[1] == 'b' && buf[2] == '\0');
250 #endif /* TEST_STRLCAT */
258 return ! (strlcpy(buf, "a", sizeof(buf)) == 1 &&
259 buf[0] == 'a' && buf[1] == '\0');
261 #endif /* TEST_STRLCPY */
264 * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
266 * Permission to use, copy, modify, and distribute this software for any
267 * purpose with or without fee is hereby granted, provided that the above
268 * copyright notice and this permission notice appear in all copies.
270 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
271 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
272 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
273 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
274 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
275 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
276 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
279 # define _OPENBSD_SOURCE
288 if (strtonum("1", 0, 2, &errstr) != 1)
292 if (strtonum("1x", 0, 2, &errstr) != 0)
296 if (strtonum("2", 0, 1, &errstr) != 0)
300 if (strtonum("0", 1, 2, &errstr) != 0)
306 #endif /* TEST_STRTONUM */
307 #if TEST_SYS_BYTEORDER_H
308 #include <sys/byteorder.h>
315 #endif /* TEST_SYS_BYTEORDER_H */
316 #if TEST_SYS_ENDIAN_H
317 #include <sys/endian.h>
324 #endif /* TEST_SYS_ENDIAN_H */
326 #include <sys/queue.h>
331 TAILQ_ENTRY(foo) entries;
334 TAILQ_HEAD(fooq, foo);
339 struct fooq foo_q, bar_q;
347 * Use TAILQ_FOREACH_SAFE because some systems (e.g., Linux)
348 * have TAILQ_FOREACH but not the safe variant.
351 TAILQ_FOREACH_SAFE(p, &foo_q, entries, tmp)
354 /* Test for newer macros as well. */
356 TAILQ_CONCAT(&foo_q, &bar_q, entries);
359 #endif /* TEST_SYS_QUEUE */
361 #include <sys/wait.h>
368 return waitpid(WAIT_ANY, &st, WNOHANG) != -1;
370 #endif /* TEST_WAIT_ANY */