xref: /openbsd/regress/lib/libc/sys/macros.h (revision 5a38ef86)
1 /*	$OpenBSD: macros.h,v 1.5 2021/12/13 16:56:48 deraadt Exp $	*/
2 /* Public domain - Moritz Buhl */
3 
4 #include <sys/socket.h>
5 #include <sys/stdint.h>
6 #include <sys/sysctl.h>
7 #include <sys/types.h>
8 
9 #include <stdbool.h>
10 #include <string.h>
11 #include <stdio.h>
12 
13 #define nitems(_a)     (sizeof((_a)) / sizeof((_a)[0]))
14 
15 #define __arraycount(_a)	nitems(_a)
16 #define __unreachable()		atf_tc_fail("unreachable")
17 #define __UNCONST(a)		(a)
18 
19 /* t_chroot.c */
20 #define fchroot(fd) 0
21 
22 /* t_clock_gettime.c */
23 int sysctlbyname(char *, void *, size_t *, void *, size_t);
24 
25 int
26 sysctlbyname(char* s, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
27 {
28         int mib[3], miblen;
29 
30 	mib[0] = CTL_KERN;
31 	if (strcmp(s, "kern.timecounter.hardware") == 0) {
32 		mib[1] = KERN_TIMECOUNTER;
33 		mib[2] = KERN_TIMECOUNTER_HARDWARE;
34 		miblen = 3;
35 	} else if (strcmp(s, "kern.timecounter.choice") == 0) {
36 		mib[1] = KERN_TIMECOUNTER;
37 		mib[2] = KERN_TIMECOUNTER_CHOICE;
38 		miblen = 3;
39 	} else if (strcmp(s, "kern.securelevel") == 0) {
40 		mib[1] = KERN_SECURELVL;
41 		miblen = 2;
42 	} else {
43 		fprintf(stderr, "%s(): mib '%s' not supported\n", __func__, s);
44 		return -42;
45 	}
46 
47         return sysctl(mib, miblen, oldp, oldlenp, newp, newlen);
48 }
49 
50 /* t_connect.c */
51 #define IPPORT_RESERVEDMAX	1023
52 
53 /* t_fork.c */
54 #define kinfo_proc2	kinfo_proc
55 #define KERN_PROC2	KERN_PROC
56 #define reallocarr(pp, n, s)	((*pp = reallocarray(*pp, n, s)), *pp == NULL)
57 #define LSSTOP		SSTOP
58 
59 /* t_mlock.c */
60 #define MAP_WIRED	__MAP_NOREPLACE
61 
62 /* t_pipe2.c */
63 #define O_NOSIGPIPE	0
64 
65 /* t_poll.c */
66 #define pollts(a, b, c, e)	0
67 
68 /* t_sendrecv.c */
69 #define SO_RERROR	SO_DEBUG
70 
71 /* t_write.c */
72 #define _PATH_DEVZERO	"/dev/zero"
73 
74 /* t_wait_noproc.c */
75 #define ___STRING(x)	#x
76 #define __BIT(n)	(1 << (n))
77