From 6cc7e96f972d9a648bef9d49ca245282250a5502 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 12 Jan 2011 16:24:23 -0800 Subject: attempt to support broken/crazy systems clock_gettime() is not available on some systems and/or CLOCK_MONOTONIC. This is totally broken considering the POSIX standard was 10 years ago, now. Nothing in gnulib, either, wtf?! http://www.gnu.org/software/gnulib/manual/html_node/clock_005fgettime.html --- ext/clogger_ext/broken_system_compat.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ext/clogger_ext/broken_system_compat.h (limited to 'ext/clogger_ext/broken_system_compat.h') diff --git a/ext/clogger_ext/broken_system_compat.h b/ext/clogger_ext/broken_system_compat.h new file mode 100644 index 0000000..f58307e --- /dev/null +++ b/ext/clogger_ext/broken_system_compat.h @@ -0,0 +1,27 @@ +/* + * this header includes functions to support broken systems + * without clock_gettime() or CLOCK_MONOTONIC + */ + +#ifndef HAVE_CLOCK_GETTIME +# ifndef CLOCK_REALTIME +# define CLOCK_REALTIME 0 /* whatever */ +# endif +static int fake_clock_gettime(int clk_id, struct timespec *res) +{ + struct timeval tv; + int r = gettimeofday(&tv, NULL); + + assert(0 == r && "gettimeofday() broke!?"); + res->tv_sec = tv.tv_sec; + res->tv_nsec = tv.tv_usec * 1000; + + return r; +} +# define clock_gettime fake_clock_gettime +#endif /* broken systems w/o clock_gettime() */ + +/* UGH */ +#ifndef _POSIX_MONOTONIC_CLOCK +# define CLOCK_MONOTONIC CLOCK_REALTIME +#endif -- cgit v1.2.3-24-ge0c7