1 #include <stdbool.h>
2 #include <stdio.h>
3 #include <unistd.h>
4
5 static struct
6 {
7 long int _P_val;
8 const char *name;
9 int _SC_val;
10 bool positive;
11 bool posix2;
12 } posix_options[] =
13 {
14 #define N_(name, pos) { _POSIX_##name, #name, _SC_##name, pos, false }
15 #define NP(name) N_ (name, true)
16 #define N(name) N_ (name, false)
17 #define N2(name) { _POSIX2_##name, #name, _SC_2_##name, false, true }
18 N (ADVISORY_INFO),
19 N (ASYNCHRONOUS_IO),
20 N (BARRIERS),
21 N (CLOCK_SELECTION),
22 N (CPUTIME),
23 N (FSYNC),
24 N (IPV6),
25 NP (JOB_CONTROL),
26 N (MAPPED_FILES),
27 N (MEMLOCK),
28 N (MEMLOCK_RANGE),
29 N (MEMORY_PROTECTION),
30 N (MESSAGE_PASSING),
31 N (MONOTONIC_CLOCK),
32 #ifdef _POSIX_PRIORITIZED_IO
33 N (PRIORITIZED_IO),
34 #endif
35 #ifdef _POSIX_PRIORITY_SCHEDULING
36 N (PRIORITY_SCHEDULING),
37 #endif
38 N (RAW_SOCKETS),
39 N (READER_WRITER_LOCKS),
40 N (REALTIME_SIGNALS),
41 NP (REGEXP),
42 NP (SAVED_IDS),
43 N (SEMAPHORES),
44 N (SHARED_MEMORY_OBJECTS),
45 NP (SHELL),
46 N (SPAWN),
47 N (SPIN_LOCKS),
48 N (SPORADIC_SERVER),
49 #ifdef _POSIX_SYNCHRONIZED_IO
50 N (SYNCHRONIZED_IO),
51 #endif
52 N (THREAD_ATTR_STACKADDR),
53 N (THREAD_ATTR_STACKSIZE),
54 N (THREAD_CPUTIME),
55 N (THREAD_PRIO_INHERIT),
56 N (THREAD_PRIO_PROTECT),
57 N (THREAD_PRIORITY_SCHEDULING),
58 N (THREAD_PROCESS_SHARED),
59 N (THREAD_SAFE_FUNCTIONS),
60 N (THREAD_SPORADIC_SERVER),
61 N (THREADS),
62 N (TIMEOUTS),
63 N (TIMERS),
64 N (TRACE),
65 N (TRACE_EVENT_FILTER),
66 N (TRACE_INHERIT),
67 N (TRACE_LOG),
68 N (TYPED_MEMORY_OBJECTS),
69 N2 (C_BIND),
70 N2 (C_DEV),
71 N2 (CHAR_TERM)
72 };
73 #define nposix_options (sizeof (posix_options) / sizeof (posix_options[0]))
74
75 static int
do_test(void)76 do_test (void)
77 {
78 int result = 0;
79
80 for (int i = 0; i < nposix_options; ++i)
81 {
82 long int scret = sysconf (posix_options[i]._SC_val);
83
84 if (scret == 0)
85 {
86 printf ("sysconf(_SC_%s%s) returned zero\n",
87 posix_options[i].posix2 ? "2_" : "", posix_options[i].name);
88 result = 1;
89 }
90 if (posix_options[i]._P_val != 0 && posix_options[i]._P_val != scret)
91 {
92 printf ("sysconf(_SC_%s%s) = %ld does not match _POSIX%s_%s = %ld\n",
93 posix_options[i].posix2 ? "2_" : "", posix_options[i].name,
94 scret,
95 posix_options[i].posix2 ? "2" : "", posix_options[i].name,
96 posix_options[i]._P_val);
97 result = 1;
98 }
99 else if (posix_options[i].positive && scret < 0)
100 {
101 printf ("sysconf(_SC_%s%s) must be > 0\n",
102 posix_options[i].posix2 ? "2_" : "", posix_options[i].name);
103 result = 1;
104 }
105
106 #define STDVER 200809L
107 if (scret > 0 && scret != STDVER && !posix_options[i].positive)
108 {
109 printf ("sysconf(_SC_%s%s) must be %ldL\n",
110 posix_options[i].posix2 ? "2_" : "", posix_options[i].name,
111 STDVER);
112 result = 1;
113 }
114 }
115
116 return result;
117 }
118
119 #define TEST_FUNCTION do_test ()
120 #include "../test-skeleton.c"
121