another try to fix systems without CLOCK_MONOTONIC
[clogger.git] / ext / clogger_ext / broken_system_compat.h
blob632612b108b54e69e5256270df1b1ef836957ccc
1 /*
2 * this header includes functions to support broken systems
3 * without clock_gettime() or CLOCK_MONOTONIC
4 */
6 #ifndef HAVE_TYPE_CLOCKID_T
7 typedef int clockid_t;
8 #endif
10 #ifndef HAVE_CLOCK_GETTIME
11 # ifndef CLOCK_REALTIME
12 # define CLOCK_REALTIME 0 /* whatever */
13 # endif
14 static int fake_clock_gettime(clockid_t clk_id, struct timespec *res)
16 struct timeval tv;
17 int r = gettimeofday(&tv, NULL);
19 assert(0 == r && "gettimeofday() broke!?");
20 res->tv_sec = tv.tv_sec;
21 res->tv_nsec = tv.tv_usec * 1000;
23 return r;
25 # define clock_gettime fake_clock_gettime
26 #endif /* broken systems w/o clock_gettime() */
29 * UGH
30 * CLOCK_MONOTONIC is not guaranteed to be a macro, either
32 #ifndef CLOCK_MONOTONIC
33 # if (!defined(_POSIX_MONOTONIC_CLOCK) || !defined(HAVE_CLOCK_MONOTONIC))
34 # define CLOCK_MONOTONIC CLOCK_REALTIME
35 # endif
36 #endif