summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: af94242)
raw | patch | inline | side by side (parent: af94242)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Fri, 26 Nov 2010 21:46:26 +0000 (22:46 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Fri, 26 Nov 2010 21:46:26 +0000 (22:46 +0100) |
… which, apparently, doesn't have clock_gettime(2).
configure.in | patch | blob | history | |
src/utils_time.c | patch | blob | history | |
src/utils_time.h | patch | blob | history |
diff --git a/configure.in b/configure.in
index fd6a25701e5c5a41c416ac53dab941f5001caee0..3b46188a3e73ea9ac4cb7be49b3db4bd1dccc2d7 100644 (file)
--- a/configure.in
+++ b/configure.in
clock_gettime_needs_rt="no"
clock_gettime_needs_posix4="no"
-AC_CHECK_FUNCS(clock_gettime,
- [],
- AC_CHECK_LIB(rt, clock_gettime,
- [clock_gettime_needs_rt="yes"],
- AC_CHECK_LIB(posix4, clock_gettime,
- [clock_gettime_needs_posix4="yes"],
- AC_MSG_ERROR(cannot find clock_gettime))))
+have_clock_gettime="no"
+AC_CHECK_FUNCS(clock_gettime, [have_clock_gettime="yes"])
+if test "x$have_clock_gettime" = "xno"
+then
+ AC_CHECK_LIB(rt, clock_gettime, [clock_gettime_needs_rt="yes"
+ have_clock_gettime="yes"])
+fi
+if test "x$have_clock_gettime" = "xno"
+then
+ AC_CHECK_LIB(posix4, clock_gettime, [clock_gettime_needs_posix4="yes"
+ have_clock_gettime="yes"])
+fi
+if test "x$have_clock_gettime" = "xyes"
+then
+ AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define if the clock_gettime(2) function is available.])
+else
+ AC_MSG_WARN(cannot find clock_gettime)
+fi
nanosleep_needs_rt="no"
nanosleep_needs_posix4="no"
diff --git a/src/utils_time.c b/src/utils_time.c
index 420b425c0bd1a2739fa398f292062867f57f3144..aac6135e28f8bf7d1be5966d5316a64c28200e93 100644 (file)
--- a/src/utils_time.c
+++ b/src/utils_time.c
#include "plugin.h"
#include "common.h"
+#if HAVE_CLOCK_GETTIME
cdtime_t cdtime (void) /* {{{ */
{
int status;
return (TIMESPEC_TO_CDTIME_T (&ts));
} /* }}} cdtime_t cdtime */
+#else
+/* Work around for Mac OS X which doesn't have clock_gettime(2). *sigh* */
+cdtime_t cdtime (void) /* {{{ */
+{
+ int status;
+ struct timeval tv = { 0, 0 };
+
+ status = gettimeofday (&tv, /* struct timezone = */ NULL);
+ if (status != 0)
+ {
+ char errbuf[1024];
+ ERROR ("cdtime: gettimeofday failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (0);
+ }
+
+ return (TIMEVAL_TO_CDTIME_T (&tv));
+} /* }}} cdtime_t cdtime */
+#endif
/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/utils_time.h b/src/utils_time.h
index da73492cc922b785b0677df828180a1b9d5ac0c6..0fd809ac5de49327044102a9eabd9b28820abdc9 100644 (file)
--- a/src/utils_time.h
+++ b/src/utils_time.h
(tvp)->tv_sec = CDTIME_T_TO_TIME_T (cdt); \
(tvp)->tv_usec = CDTIME_T_TO_US ((cdt) % 1073741824); \
} while (0)
-#define TIMEVAL_TO_CDTIME_T(tv) (TIME_T_TO_CDTIME_T ((tv).tv_sec) \
- + US_TO_CDTIME_T ((tv).tv_usec))
+#define TIMEVAL_TO_CDTIME_T(tv) (TIME_T_TO_CDTIME_T ((tv)->tv_sec) \
+ + US_TO_CDTIME_T ((tv)->tv_usec))
#define CDTIME_T_TO_TIMESPEC(cdt,tsp) do { \
(tsp)->tv_sec = CDTIME_T_TO_TIME_T (cdt); \