1 /* Test setting the monotonic clock. */ 2 3 #include <time.h> 4 #include <unistd.h> 5 6 #if defined CLOCK_MONOTONIC && defined _POSIX_MONOTONIC_CLOCK 7 8 # include <errno.h> 9 # include <stdio.h> 10 11 static int do_test(void)12do_test (void) 13 { 14 if (sysconf (_SC_MONOTONIC_CLOCK) <= 0) 15 return 0; 16 17 struct timespec ts; 18 if (clock_gettime (CLOCK_MONOTONIC, &ts) != 0) 19 { 20 puts ("clock_gettime(CLOCK_MONOTONIC) failed"); 21 return 1; 22 } 23 24 /* Setting the monotonic clock must fail. */ 25 if (clock_settime (CLOCK_MONOTONIC, &ts) != -1) 26 { 27 puts ("clock_settime(CLOCK_MONOTONIC) did not fail"); 28 return 1; 29 } 30 if (errno != EINVAL) 31 { 32 printf ("clock_settime(CLOCK_MONOTONIC) set errno to %d, expected %d\n", 33 errno, EINVAL); 34 return 1; 35 } 36 return 0; 37 } 38 # define TEST_FUNCTION do_test () 39 40 #else 41 # define TEST_FUNCTION 0 42 #endif 43 #include "../test-skeleton.c" 44