#include #include int main (int argc, char **argv) { int clock = argc == 1 ? CLOCK_REALTIME : CLOCK_REALTIME_COARSE; for (unsigned int i = 1; i; i++) { struct timespec ts; if (clock_gettime (clock, &ts)) { perror ("clock_gettime"); return 1; } time_t x = time (0); if (x < ts.tv_sec) { printf ("clock_gettime (%s, ...)" " yielded a seconds count of %ld;\n" "then time (0) yielded a seconds count of %ld," " which was %ld s earlier.\n" "Time warp!\n", (clock == CLOCK_REALTIME ? "CLOCK_REALTIME" : "CLOCK_REALTIME_COARSE"), (long) ts.tv_sec, (long) x, (long) (ts.tv_sec - x)); return 1; } } return 0; }