diff options
Diffstat (limited to 'usr/src/lib/libresolv2/common/bsd/gettimeofday.c')
-rw-r--r-- | usr/src/lib/libresolv2/common/bsd/gettimeofday.c | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/usr/src/lib/libresolv2/common/bsd/gettimeofday.c b/usr/src/lib/libresolv2/common/bsd/gettimeofday.c index 68b5ca39a0..2926a3575e 100644 --- a/usr/src/lib/libresolv2/common/bsd/gettimeofday.c +++ b/usr/src/lib/libresolv2/common/bsd/gettimeofday.c @@ -1,20 +1,47 @@ -/* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - #ifndef LINT -static const char rcsid[] = "$Id: gettimeofday.c,v 8.4 1999/10/13 16:39:21 vixie Exp $"; +static const char rcsid[] = "$Id: gettimeofday.c,v 1.4 2005/04/27 04:56:11 sra Exp $"; #endif - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" +#include <stdio.h> +#include <syslog.h> +#include <sys/time.h> #include "port_after.h" #if !defined(NEED_GETTIMEOFDAY) -int __bindcompat_gettimeofday; +/*% + * gettimeofday() occasionally returns invalid tv_usec on some platforms. + */ +#define MILLION 1000000 +#undef gettimeofday + +int +isc__gettimeofday(struct timeval *tp, struct timezone *tzp) { + int res; + + res = gettimeofday(tp, tzp); + if (res < 0) + return (res); + if (tp == NULL) + return (res); + if (tp->tv_usec < 0) { + do { + tp->tv_usec += MILLION; + tp->tv_sec--; + } while (tp->tv_usec < 0); + goto log; + } else if (tp->tv_usec > MILLION) { + do { + tp->tv_usec -= MILLION; + tp->tv_sec++; + } while (tp->tv_usec > MILLION); + goto log; + } + return (res); + log: + syslog(LOG_ERR, "gettimeofday: tv_usec out of range\n"); + return (res); +} #else int gettimeofday(struct timeval *tvp, struct _TIMEZONE *tzp) { |