Back to index

glibc  2.9
tst-sysconf.c
Go to the documentation of this file.
00001 #include <stdbool.h>
00002 #include <stdio.h>
00003 #include <unistd.h>
00004 
00005 static struct
00006 {
00007   long int _P_val;
00008   const char *name;
00009   int _SC_val;
00010   bool positive;
00011   bool posix2;
00012 } posix_options[] =
00013   {
00014 #define N_(name, pos) { _POSIX_##name, #name, _SC_##name, pos, false }
00015 #define NP(name) N_ (name, true)
00016 #define N(name) N_ (name, false)
00017 #define N2(name) { _POSIX2_##name, #name, _SC_2_##name, false, true }
00018     N (ADVISORY_INFO),
00019     N (ASYNCHRONOUS_IO),
00020     N (BARRIERS),
00021     N (CLOCK_SELECTION),
00022     N (CPUTIME),
00023     N (FSYNC),
00024     N (IPV6),
00025     NP (JOB_CONTROL),
00026     N (MAPPED_FILES),
00027     N (MEMLOCK),
00028     N (MEMLOCK_RANGE),
00029     N (MEMORY_PROTECTION),
00030     N (MESSAGE_PASSING),
00031     N (MONOTONIC_CLOCK),
00032     N (PRIORITIZED_IO),
00033     N (PRIORITY_SCHEDULING),
00034     N (RAW_SOCKETS),
00035     N (READER_WRITER_LOCKS),
00036     N (REALTIME_SIGNALS),
00037     NP (REGEXP),
00038     NP (SAVED_IDS),
00039     N (SEMAPHORES),
00040     N (SHARED_MEMORY_OBJECTS),
00041     NP (SHELL),
00042     N (SPAWN),
00043     N (SPIN_LOCKS),
00044     N (SPORADIC_SERVER),
00045     N (SYNCHRONIZED_IO),
00046     N (THREAD_ATTR_STACKADDR),
00047     N (THREAD_ATTR_STACKSIZE),
00048     N (THREAD_CPUTIME),
00049     N (THREAD_PRIO_INHERIT),
00050     N (THREAD_PRIO_PROTECT),
00051     N (THREAD_PRIORITY_SCHEDULING),
00052     N (THREAD_PROCESS_SHARED),
00053     N (THREAD_SAFE_FUNCTIONS),
00054     N (THREAD_SPORADIC_SERVER),
00055     N (THREADS),
00056     N (TIMEOUTS),
00057     N (TIMERS),
00058     N (TRACE),
00059     N (TRACE_EVENT_FILTER),
00060     N (TRACE_INHERIT),
00061     N (TRACE_LOG),
00062     N (TYPED_MEMORY_OBJECTS),
00063     N2 (C_BIND),
00064     N2 (C_DEV),
00065     N2 (CHAR_TERM)
00066   };
00067 #define nposix_options (sizeof (posix_options) / sizeof (posix_options[0]))
00068 
00069 static int
00070 do_test (void)
00071 {
00072   int result = 0;
00073 
00074   for (int i = 0; i < nposix_options; ++i)
00075     {
00076       long int scret = sysconf (posix_options[i]._SC_val);
00077 
00078       if (scret == 0)
00079        {
00080          printf ("sysconf(_SC_%s%s) returned zero\n",
00081                 posix_options[i].posix2 ? "2_" : "", posix_options[i].name);
00082          result = 1;
00083        }
00084       if (posix_options[i]._P_val != 0 && posix_options[i]._P_val != scret)
00085        {
00086          printf ("sysconf(_SC_%s%s) = %ld does not match _POSIX%s_%s = %ld\n",
00087                 posix_options[i].posix2 ? "2_" : "", posix_options[i].name,
00088                 scret,
00089                 posix_options[i].posix2 ? "2" : "", posix_options[i].name,
00090                 posix_options[i]._P_val);
00091          result = 1;
00092        }
00093       else if (posix_options[i].positive && scret < 0)
00094        {
00095          printf ("sysconf(_SC_%s%s) must be > 0\n",
00096                 posix_options[i].posix2 ? "2_" : "", posix_options[i].name);
00097          result = 1;
00098        }
00099 
00100 #define STDVER 200112L
00101       if (scret > 0 && scret != STDVER && !posix_options[i].positive)
00102        {
00103          printf ("sysconf(_SC_%s%s) must be %ldL\n",
00104                 posix_options[i].posix2 ? "2_" : "", posix_options[i].name,
00105                 STDVER);
00106          result = 1;
00107        }
00108     }
00109 
00110   return result;
00111 }
00112 
00113 #define TEST_FUNCTION do_test ()
00114 #include "../test-skeleton.c"