Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / bind / bsd / gettimeofday.c
blobffde0202134b1244d428d475b2ac3da6d72bca17
1 #ifndef LINT
2 static const char rcsid[] = "$Id: gettimeofday.c,v 1.1.2.2 2002/07/12 00:49:51 marka Exp $";
3 #endif
5 #include "port_before.h"
6 #include <stdio.h>
7 #include <syslog.h>
8 #include <sys/time.h>
9 #include "port_after.h"
11 #if !defined(NEED_GETTIMEOFDAY)
13 * gettimeofday() occasionally returns invalid tv_usec on some platforms.
15 #define MILLION 1000000
16 #undef gettimeofday
18 int
19 isc__gettimeofday(struct timeval *tp, struct timezone *tzp) {
20 int res;
22 res = gettimeofday(tp, tzp);
23 if (res < 0)
24 return (res);
25 if (tp == NULL)
26 return (res);
27 if (tp->tv_usec < 0) {
28 do {
29 tp->tv_usec += MILLION;
30 tp->tv_sec--;
31 } while (tp->tv_usec < 0);
32 goto log;
33 } else if (tp->tv_usec > MILLION) {
34 do {
35 tp->tv_usec -= MILLION;
36 tp->tv_sec++;
37 } while (tp->tv_usec > MILLION);
38 goto log;
40 return (res);
41 log:
42 syslog(LOG_ERR, "gettimeofday: tv_usec out of range\n");
43 return (res);
45 #else
46 int
47 gettimeofday(struct timeval *tvp, struct _TIMEZONE *tzp) {
48 time_t clock, time(time_t *);
50 if (time(&clock) == (time_t) -1)
51 return (-1);
52 if (tvp) {
53 tvp->tv_sec = clock;
54 tvp->tv_usec = 0;
56 if (tzp) {
57 tzp->tz_minuteswest = 0;
58 tzp->tz_dsttime = 0;
60 return (0);
62 #endif /*NEED_GETTIMEOFDAY*/