aboutsummaryrefslogtreecommitdiff
path: root/lib/timeval.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2008-07-02 03:04:56 +0000
committerYang Tse <yangsita@gmail.com>2008-07-02 03:04:56 +0000
commit97333deb3f6713d7d12168c8980d69cc60961063 (patch)
tree6c792c1b43a9de7cf829f7dc618a2379797da653 /lib/timeval.c
parent400d9d420517a81d5f55153b0dda90aced1cbfb3 (diff)
fallback to gettimeofday when monotonic clock is unavailable at run-time
Diffstat (limited to 'lib/timeval.c')
-rw-r--r--lib/timeval.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/timeval.c b/lib/timeval.c
index 74f0b3a2f..25ae76329 100644
--- a/lib/timeval.c
+++ b/lib/timeval.c
@@ -52,9 +52,24 @@ struct timeval curlx_tvnow(void)
*/
struct timeval now;
struct timespec tsnow;
- (void)clock_gettime(CLOCK_MONOTONIC, &tsnow);
- now.tv_sec = tsnow.tv_sec;
- now.tv_usec = tsnow.tv_nsec / 1000;
+ if(0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) {
+ now.tv_sec = tsnow.tv_sec;
+ now.tv_usec = tsnow.tv_nsec / 1000;
+ }
+ /*
+ ** Even when the configure process has truly detected monotonic clock
+ ** availability, it might happen that it is not actually available at
+ ** run-time. When this occurs simply fallback to other time source.
+ */
+#ifdef HAVE_GETTIMEOFDAY
+ else
+ (void)gettimeofday(&now, NULL);
+#else
+ else {
+ now.tv_sec = (long)time(NULL);
+ now.tv_usec = 0;
+ }
+#endif
return now;
}