Back to index

glibc  2.9
tst-clock2.c
Go to the documentation of this file.
00001 /* Test setting the monotonic clock.  */
00002 
00003 #include <time.h>
00004 #include <unistd.h>
00005 
00006 #if defined CLOCK_MONOTONIC && defined _POSIX_MONOTONIC_CLOCK
00007 
00008 # include <errno.h>
00009 # include <stdio.h>
00010 
00011 static int
00012 do_test (void)
00013 {
00014   if (sysconf (_SC_MONOTONIC_CLOCK) <= 0)
00015     return 0;
00016 
00017   struct timespec ts;
00018   if (clock_gettime (CLOCK_MONOTONIC, &ts) != 0)
00019     {
00020       puts ("clock_gettime(CLOCK_MONOTONIC) failed");
00021       return 1;
00022     }
00023 
00024   /* Setting the monotonic clock must fail.  */
00025   if (clock_settime (CLOCK_MONOTONIC, &ts) != -1)
00026     {
00027       puts ("clock_settime(CLOCK_MONOTONIC) did not fail");
00028       return 1;
00029     }
00030   if (errno != EINVAL)
00031     {
00032       printf ("clock_settime(CLOCK_MONOTONIC) set errno to %d, expected %d\n",
00033              errno, EINVAL);
00034       return 1;
00035     }
00036   return 0;
00037 }
00038 # define TEST_FUNCTION do_test ()
00039 
00040 #else
00041 # define TEST_FUNCTION      0
00042 #endif
00043 #include "../test-skeleton.c"