From 489ff32763f7b41fef7362f5936f656d1bf67e14 Mon Sep 17 00:00:00 2001 From: des Date: Thu, 19 Jul 2007 11:01:36 +0000 Subject: [PATCH] If clock_gettime() is not available, use gettimeofday() directly. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1716 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/lib/libvarnish/time.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/varnish-cache/lib/libvarnish/time.c b/varnish-cache/lib/libvarnish/time.c index 66c4a251..f2a375d0 100644 --- a/varnish-cache/lib/libvarnish/time.c +++ b/varnish-cache/lib/libvarnish/time.c @@ -46,32 +46,44 @@ * */ +#include + #include #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "libvarnish.h" double TIM_mono(void) { +#ifdef HAVE_CLOCK_GETTIME struct timespec ts; assert(clock_gettime(CLOCK_MONOTONIC, &ts) == 0); return (ts.tv_sec + 1e-9 * ts.tv_nsec); +#else + struct timeval tv; + + assert(gettimeofday(&tv, NULL) == 0); + return (tv.tv_sec + 1e-6 * tv.tv_usec); +#endif } double TIM_real(void) { +#ifdef HAVE_CLOCK_GETTIME struct timespec ts; assert(clock_gettime(CLOCK_REALTIME, &ts) == 0); return (ts.tv_sec + 1e-9 * ts.tv_nsec); +#else + struct timeval tv; + + assert(gettimeofday(&tv, NULL) == 0); + return (tv.tv_sec + 1e-6 * tv.tv_usec); +#endif } void @@ -85,9 +97,10 @@ TIM_format(time_t t, char *p) /* XXX: add statistics ? */ static const char *fmts[] = { - "%a, %d %b %Y %T GMT", /* RFC 822 & RFC1123 */ - "%A, %d-%b-%y %T GMT", /* RFC850 */ + "%a, %d %b %Y %T GMT", /* RFC 822 & RFC 1123 */ + "%A, %d-%b-%y %T GMT", /* RFC 850 */ "%a %b %d %T %Y", /* ANSI-C asctime() */ + "%F %T", /* ISO 8601 */ NULL }; -- 2.39.5