From: Mark Eichin Date: Wed, 6 Jul 1994 17:28:54 +0000 (+0000) Subject: add gmt_mktime to support new asn1 code X-Git-Tag: krb5-1.0-beta4.2~158 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=28592cb0796db445b211b924c3137591f802826d;p=krb5.git add gmt_mktime to support new asn1 code git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@3952 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 7369f7d5d..0ec1c8a94 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,9 @@ +Wed Jul 6 13:26:59 1994 Mark Eichin (eichin@cygnus.com) + + * gmt_mktime.c (gmt_mktime): New file, new function. Similar to + POSIX mktime, but always works in GMT. + configure.in, Makefile.in: build gmt_mktime. + Wed Jun 22 15:49:30 1994 Theodore Y. Ts'o (tytso at tsx-11) * locate_kdc.c (krb5_locate_kdc): Fixed default port numbers so diff --git a/src/lib/krb5/os/Makefile.in b/src/lib/krb5/os/Makefile.in index ed62f37da..e0edc9d0b 100644 --- a/src/lib/krb5/os/Makefile.in +++ b/src/lib/krb5/os/Makefile.in @@ -13,6 +13,7 @@ OBJS= \ get_krbhst.o \ gen_port.o \ gen_rname.o \ + gmt_mktime.o \ hst_realm.o \ krbfileio.o \ ktdefname.o \ @@ -44,6 +45,7 @@ SRCS= \ $(srcdir)/get_krbhst.c \ $(srcdir)/gen_port.c \ $(srcdir)/gen_rname.c \ + $(srcdir)/gmt_mktime.c \ $(srcdir)/hst_realm.c \ $(srcdir)/krbfileio.c \ $(srcdir)/ktdefname.c \ diff --git a/src/lib/krb5/os/configure.in b/src/lib/krb5/os/configure.in index 9987e9451..4da1e1f7b 100644 --- a/src/lib/krb5/os/configure.in +++ b/src/lib/krb5/os/configure.in @@ -1,4 +1,9 @@ AC_INIT(configure.in) +dnl time checks are for timeofday.c (which gets them from osconf.h) +dnl and gmt_mktime.c (which only gets them from here...) +AC_TIME_WITH_SYS_TIME +AC_HEADER_CHECK(sys/time.h,AC_DEFINE(USE_SYS_TIME_H)) +AC_HEADER_EGREP(time_t, sys/types.h, AC_DEFINE(POSIX_TYPES)) WITH_CCOPTS AC_SET_BUILDTOP CONFIG_RULES diff --git a/src/lib/krb5/os/gmt_mktime.c b/src/lib/krb5/os/gmt_mktime.c new file mode 100644 index 000000000..d4e759d17 --- /dev/null +++ b/src/lib/krb5/os/gmt_mktime.c @@ -0,0 +1,74 @@ +/* This code placed in the public domain by Mark W. Eichin */ + +#include + +#include +#include +#ifdef USE_SYS_TIME_H +#include +#endif + +/* take a struct tm, return seconds from GMT epoch */ +/* like mktime, this ignores tm_wday and tm_yday. */ +/* unlike mktime, this does not set them... it only passes a return value. */ + +static days_in_month[12] = { +0, /* jan 31 */ +31, /* feb 28 */ +59, /* mar 31 */ +90, /* apr 30 */ +120, /* may 31 */ +151, /* jun 30 */ +181, /* jul 31 */ +212, /* aug 31 */ +243, /* sep 30 */ +273, /* oct 31 */ +304, /* nov 30 */ +334 /* dec 31 */ +}; + +#define hasleapday(year) (year%400?(year%100?(year%4?0:1):0):1) + +time_t gmt_mktime(t) + struct tm* t; +{ + time_t accum; + +#define assert_time(cnd) if(!(cnd)) return -1 + + assert_time(t->tm_year>=70); + assert_time(t->tm_year<=138); + assert_time(t->tm_mon>=0); + assert_time(t->tm_mon<=11); + assert_time(t->tm_mday>=0); + assert_time(t->tm_mday<=31); + assert_time(t->tm_hour>=0); + assert_time(t->tm_hour<=23); + assert_time(t->tm_min>=0); + assert_time(t->tm_min<=59); + assert_time(t->tm_sec>=0); + assert_time(t->tm_sec<=62); + +#undef assert_time + + + accum = t->tm_year - 70; + accum *= 365; /* 365 days/normal year */ + + /* add in leap day for all previous years */ + accum += (t->tm_year - 68) / 4; + /* add in leap day for this year */ + if(t->tm_mon >= 2) /* march or later */ + if(hasleapday(t->tm_year)) accum += 1; + + accum += days_in_month[t->tm_mon]; + accum += t->tm_mday-1; /* days of month are the only 1-based field */ + accum *= 24; /* 24 hour/day */ + accum += t->tm_hour; + accum *= 60; /* 60 minute/hour */ + accum += t->tm_min; + accum *= 60; /* 60 seconds/minute */ + accum += t->tm_sec; + + return accum; +}