X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=lib%2Fgettime.c;fp=lib%2Fgettime.c;h=0000000000000000000000000000000000000000;hb=b7a32e2d73e3ab1add8208d3e157f7269a31ef4d;hp=01703bbbc18b4559f3b2003a968259d931061a78;hpb=ac902a8299ff4469b356836f431ead31c3377377;p=innduct.git diff --git a/lib/gettime.c b/lib/gettime.c deleted file mode 100644 index 01703bb..0000000 --- a/lib/gettime.c +++ /dev/null @@ -1,80 +0,0 @@ -/* $Id: gettime.c 4135 2000-10-19 16:38:13Z kondou $ -** -** Find and return time information portably. -*/ -#include "config.h" -#include "libinn.h" - -#ifdef HAVE_UNISTD_H -# include -#endif - -#ifdef TIME_WITH_SYS_TIME -# include -# include -#else -# ifdef HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif - - -int -GetTimeInfo(TIMEINFO *Now) -{ - static time_t NextHour; - static long LastTzone; - struct tm *tm; - int secondsUntilNextHour; - - struct timeval tv; - -#ifndef HAVE_TM_GMTOFF - struct tm local; - struct tm gmt; -#endif - - /* Get the basic time. */ - if (gettimeofday(&tv, (struct timezone *) 0) == -1) - return -1; - Now->time = tv.tv_sec; - Now->usec = tv.tv_usec; - - /* Now get the timezone if the last time < HH:00:00 <= now for some HH. */ - if (NextHour <= Now->time) { - tm = localtime(&Now->time); - if (tm == NULL) - return -1; - secondsUntilNextHour = 60 * (60 - tm->tm_min) - tm->tm_sec; - -#ifdef HAVE_TM_GMTOFF - LastTzone = (0 - tm->tm_gmtoff) / 60; -#else - /* To get the timezone, compare localtime with GMT. */ - local = *tm; - if ((tm = gmtime(&Now->time)) == NULL) - return -1; - gmt = *tm; - - /* Assume we are never more than 24 hours away. */ - LastTzone = gmt.tm_yday - local.tm_yday; - if (LastTzone > 1) - LastTzone = -24; - else if (LastTzone < -1) - LastTzone = 24; - else - LastTzone *= 24; - - /* Scale in the hours and minutes; ignore seconds. */ - LastTzone += gmt.tm_hour - local.tm_hour; - LastTzone *= 60; - LastTzone += gmt.tm_min - local.tm_min; -#endif /* defined(HAVE_TM_GMTOFF) */ - - NextHour = Now->time + secondsUntilNextHour; - } - Now->tzone = LastTzone; - return 0; -}