forked from krb5/krb5-anonsvn
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add gmt_mktime to support new asn1 code
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@3952 dc483132-0cff-0310-8789-dd5450dbe970
- Loading branch information
eichin
committed
Jul 6, 1994
1 parent
dd52cc1
commit 659528e
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* This code placed in the public domain by Mark W. Eichin */ | ||
|
||
#include <stdio.h> | ||
|
||
#include <sys/types.h> | ||
#include <time.h> | ||
#ifdef USE_SYS_TIME_H | ||
#include <sys/time.h> | ||
#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; | ||
} |