From: des Date: Thu, 19 Jul 2007 11:01:36 +0000 (+0000) Subject: If clock_gettime() is not available, use gettimeofday() directly. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=489ff32763f7b41fef7362f5936f656d1bf67e14;p=varnish 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 --- 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 };