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