Blob


1 #if TEST___PROGNAME
2 int
3 main(void)
4 {
5 extern char *__progname;
7 return !__progname;
8 }
9 #endif /* TEST___PROGNAME */
10 #if TEST_ENDIAN_H
11 #ifdef __linux__
12 # define _DEFAULT_SOURCE
13 #endif
14 #include <endian.h>
16 int
17 main(void)
18 {
19 return !htole32(23);
20 }
21 #endif /* TEST_ENDIAN_H */
22 #if TEST_ERR
23 /*
24 * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
25 *
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.
29 *
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.
37 */
39 #include <err.h>
40 #include <errno.h>
42 int
43 main(void)
44 {
45 warnx("%d. warnx", 1);
46 warnc(ENOENT, "%d. warn", ENOENT);
47 warn("%d. warn", 2);
48 err(0, "%d. err", 3);
49 errx(0, "%d. err", 3);
50 errc(0, ENOENT, "%d. err", 3);
51 /* NOTREACHED */
52 return 1;
53 }
54 #endif /* TEST_ERR */
55 #if TEST_GETDTABLECOUNT
56 #include <unistd.h>
58 int
59 main(void)
60 {
61 return getdtablecount() == 0;
62 }
63 #endif /* TEST_GETDTABLECOUNT */
64 #if TEST_GETEXECNAME
65 #include <stdlib.h>
67 int
68 main(void)
69 {
70 const char * progname;
72 progname = getexecname();
73 return progname == NULL;
74 }
75 #endif /* TEST_GETEXECNAME */
76 #if TEST_GETPROGNAME
77 #include <stdlib.h>
79 int
80 main(void)
81 {
82 const char * progname;
84 progname = getprogname();
85 return progname == NULL;
86 }
87 #endif /* TEST_GETPROGNAME */
88 #if TEST_LIBEVENT
89 #include <event.h>
91 int
92 main(void)
93 {
94 struct event ev;
96 event_set(&ev, 0, EV_READ, NULL, NULL);
97 event_add(&ev, NULL);
98 event_del(&ev);
99 return 0;
101 #endif /* TEST_LIBEVENT */
102 #if TEST_LIBEVENT2
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>
112 int
113 main(void)
115 struct event ev;
117 event_set(&ev, 0, EV_READ, NULL, NULL);
118 event_add(&ev, NULL);
119 event_del(&ev);
120 return 0;
122 #endif /* TEST_LIBEVENT2 */
123 #if TEST_LIB_SOCKET
124 #include <sys/socket.h>
126 int
127 main(void)
129 int fds[2], c;
131 c = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
132 return c == -1;
134 #endif /* TEST_LIB_SOCKET */
135 #if TEST_OSBYTEORDER_H
136 #include <libkern/OSByteOrder.h>
138 int
139 main(void)
141 return !OSSwapHostToLittleInt32(23);
143 #endif /* TEST_OSBYTEORDER_H */
144 #if TEST_PATH_MAX
145 /*
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
157 * allows that.
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.
164 */
166 #include <limits.h>
167 #include <stdio.h>
169 int
170 main(void)
172 printf("PATH_MAX is defined to be %ld\n", (long)PATH_MAX);
173 return 0;
175 #endif /* TEST_PATH_MAX */
176 #if TEST_PLEDGE
177 #include <unistd.h>
179 int
180 main(void)
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) */
187 #include <errno.h>
189 int
190 main(void)
193 return !program_invocation_short_name;
195 #endif /* TEST_PROGRAM_INVOCATION_SHORT_NAME */
196 #if TEST_SETRESGID
197 #define _GNU_SOURCE /* linux */
198 #include <sys/types.h>
199 #include <unistd.h>
201 int
202 main(void)
204 return setresgid(-1, -1, -1) == -1;
206 #endif /* TEST_SETRESGID */
207 #if TEST_SETRESUID
208 #define _GNU_SOURCE /* linux */
209 #include <sys/types.h>
210 #include <unistd.h>
212 int
213 main(void)
215 return setresuid(-1, -1, -1) == -1;
217 #endif /* TEST_SETRESUID */
218 #if TEST_SOCK_NONBLOCK
219 /*
220 * Linux doesn't (always?) have this.
221 */
223 #include <sys/socket.h>
225 int
226 main(void)
228 int fd[2];
229 socketpair(AF_UNIX, SOCK_STREAM|SOCK_NONBLOCK, 0, fd);
230 return 0;
232 #endif /* TEST_SOCK_NONBLOCK */
233 #if TEST_STATIC
234 int
235 main(void)
237 return 0; /* not meant to do anything */
239 #endif /* TEST_STATIC */
240 #if TEST_STRLCAT
241 #include <string.h>
243 int
244 main(void)
246 char buf[3] = "a";
247 return ! (strlcat(buf, "b", sizeof(buf)) == 2 &&
248 buf[0] == 'a' && buf[1] == 'b' && buf[2] == '\0');
250 #endif /* TEST_STRLCAT */
251 #if TEST_STRLCPY
252 #include <string.h>
254 int
255 main(void)
257 char buf[2] = "";
258 return ! (strlcpy(buf, "a", sizeof(buf)) == 1 &&
259 buf[0] == 'a' && buf[1] == '\0');
261 #endif /* TEST_STRLCPY */
262 #if TEST_STRTONUM
263 /*
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.
277 */
278 #ifdef __NetBSD__
279 # define _OPENBSD_SOURCE
280 #endif
281 #include <stdlib.h>
283 int
284 main(void)
286 const char *errstr;
288 if (strtonum("1", 0, 2, &errstr) != 1)
289 return 1;
290 if (errstr != NULL)
291 return 2;
292 if (strtonum("1x", 0, 2, &errstr) != 0)
293 return 3;
294 if (errstr == NULL)
295 return 4;
296 if (strtonum("2", 0, 1, &errstr) != 0)
297 return 5;
298 if (errstr == NULL)
299 return 6;
300 if (strtonum("0", 1, 2, &errstr) != 0)
301 return 7;
302 if (errstr == NULL)
303 return 8;
304 return 0;
306 #endif /* TEST_STRTONUM */
307 #if TEST_SYS_BYTEORDER_H
308 #include <sys/byteorder.h>
310 int
311 main(void)
313 return !LE_32(23);
315 #endif /* TEST_SYS_BYTEORDER_H */
316 #if TEST_SYS_ENDIAN_H
317 #include <sys/endian.h>
319 int
320 main(void)
322 return !htole32(23);
324 #endif /* TEST_SYS_ENDIAN_H */
325 #if TEST_SYS_QUEUE
326 #include <sys/queue.h>
327 #include <stddef.h>
329 struct foo {
330 int bar;
331 TAILQ_ENTRY(foo) entries;
332 };
334 TAILQ_HEAD(fooq, foo);
336 int
337 main(void)
339 struct fooq foo_q, bar_q;
340 struct foo *p, *tmp;
341 int i = 0;
343 TAILQ_INIT(&foo_q);
344 TAILQ_INIT(&bar_q);
346 /*
347 * Use TAILQ_FOREACH_SAFE because some systems (e.g., Linux)
348 * have TAILQ_FOREACH but not the safe variant.
349 */
351 TAILQ_FOREACH_SAFE(p, &foo_q, entries, tmp)
352 p->bar = i++;
354 /* Test for newer macros as well. */
356 TAILQ_CONCAT(&foo_q, &bar_q, entries);
357 return 0;
359 #endif /* TEST_SYS_QUEUE */
360 #if TEST_WAIT_ANY
361 #include <sys/wait.h>
363 int
364 main(void)
366 int st;
368 return waitpid(WAIT_ANY, &st, WNOHANG) != -1;
370 #endif /* TEST_WAIT_ANY */