fielding 96/10/30 04:44:04
Modified: src util_date.c Log: Removed restriction on 2038 for systems with better-than-32bit representations of time_t variables. Revision Changes Path 1.2 +16 -23 apache/src/util_date.c Index: util_date.c =================================================================== RCS file: /export/home/cvs/apache/src/util_date.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C3 -r1.1 -r1.2 *** util_date.c 1996/10/27 10:36:29 1.1 --- util_date.c 1996/10/30 12:44:03 1.2 *************** *** 52,59 **** /* * util_date.c: date parsing utility routines ! * These routines are (hopefully) platform-independent aside from ! * the limitations of Unix time (must fit inside a signed long). * * 27 Oct 1996 Roy Fielding * Extracted (with many modifications) from mod_proxy.c and --- 52,58 ---- /* * util_date.c: date parsing utility routines ! * These routines are (hopefully) platform-independent. * * 27 Oct 1996 Roy Fielding * Extracted (with many modifications) from mod_proxy.c and *************** *** 112,130 **** * * The return value is always a valid time_t value -- (time_t)0 is returned * if the input date is outside that capable of being represented by time(), ! * i.e., outside Thu, 01 Jan 1970 00:00:00 to 01 Jan 2038 00:00:00. * * This routine is intended to be very fast, much faster than mktime(). */ time_t tm2sec(const struct tm *t) { int year; ! long days; const int dayoffset[12] = {306, 337, 0, 31, 61, 92, 122, 153, 184, 214, 245, 275}; year = t->tm_year; ! if (year < 70 || year >= 138) /* Most OSes have a limited range */ return BAD_DATE; /* shift new year to 1st March in order to make leap year calc easy */ --- 111,131 ---- * * The return value is always a valid time_t value -- (time_t)0 is returned * if the input date is outside that capable of being represented by time(), ! * i.e., before Thu, 01 Jan 1970 00:00:00 for all systems and ! * beyond 2038 for 32bit systems. * * This routine is intended to be very fast, much faster than mktime(). */ time_t tm2sec(const struct tm *t) { int year; ! time_t days; const int dayoffset[12] = {306, 337, 0, 31, 61, 92, 122, 153, 184, 214, 245, 275}; year = t->tm_year; ! ! if (year < 70 || ((sizeof(time_t) <= 4) && (year >= 138))) return BAD_DATE; /* shift new year to 1st March in order to make leap year calc easy */ *************** *** 132,140 **** if (t->tm_mon < 2) year--; /* Find number of days since 1st March 1900 (in the Gregorian calendar). */ - /* Because year 2000 is a leap year, we don't need to adjust for century */ ! days = year * 365 + year/4; days += dayoffset[t->tm_mon] + t->tm_mday - 1; days -= 25508; /* 1 jan 1970 is 25508 days since 1 mar 1900 */ --- 133,140 ---- if (t->tm_mon < 2) year--; /* Find number of days since 1st March 1900 (in the Gregorian calendar). */ ! days = year * 365 + year/4 - year/100 + (year/100 + 3)/4; days += dayoffset[t->tm_mon] + t->tm_mday - 1; days -= 25508; /* 1 jan 1970 is 25508 days since 1 mar 1900 */ *************** *** 143,149 **** if (days < 0) return BAD_DATE; /* must have overflowed */ else ! return (time_t)days; /* must be a valid time */ } /* --- 143,149 ---- if (days < 0) return BAD_DATE; /* must have overflowed */ else ! return days; /* must be a valid time */ } /* *************** *** 222,232 **** /* start of the actual date information for all 3 formats. */ if (checkmask(date, "## @$$ #### ##:##:## *")) { /* RFC 1123 format */ ! if ((date[7] == '1') && (date[8] == '9')) ! ds.tm_year = 0; ! else if ((date[7] == '2') && (date[8] == '0')) ! ds.tm_year = 100; ! else return BAD_DATE; ds.tm_year += ((date[9] - '0') * 10) + (date[10] - '0'); --- 222,229 ---- /* start of the actual date information for all 3 formats. */ if (checkmask(date, "## @$$ #### ##:##:## *")) { /* RFC 1123 format */ ! ds.tm_year = ((date[7] - '0') * 10 + (date[8] - '0') - 19) * 100; ! if (ds.tm_year < 0) return BAD_DATE; ds.tm_year += ((date[9] - '0') * 10) + (date[10] - '0'); *************** *** 247,257 **** timstr = date + 10; } else if (checkmask(date, "@$$ ~# ##:##:## ####*")) { /* asctime format */ ! if ((date[16] == '1') && (date[17] == '9')) ! ds.tm_year = 0; ! else if ((date[16] == '2') && (date[17] == '0')) ! ds.tm_year = 100; ! else return BAD_DATE; ds.tm_year += ((date[18] - '0') * 10) + (date[19] - '0'); --- 244,251 ---- timstr = date + 10; } else if (checkmask(date, "@$$ ~# ##:##:## ####*")) { /* asctime format */ ! ds.tm_year = ((date[16] - '0') * 10 + (date[17] - '0') - 19) * 100; ! if (ds.tm_year < 0) return BAD_DATE; ds.tm_year += ((date[18] - '0') * 10) + (date[19] - '0'); *************** *** 288,299 **** if ((ds.tm_mday == 31) && (mon == 3 || mon == 5 || mon == 8 || mon == 10)) return BAD_DATE; ! /* February gets special check for leapyear, but we don't have to worry */ ! /* about 100 and 400 year adjustments since 2000 is a special leap year */ ! /* Note also that (ds.tm_year & 3) == (ds.tm_year % 4). */ ! if ((mon == 1) && ! ((ds.tm_mday > 29) || ((ds.tm_mday == 29) && (ds.tm_year & 3)))) return BAD_DATE; ds.tm_mon = mon; --- 282,292 ---- if ((ds.tm_mday == 31) && (mon == 3 || mon == 5 || mon == 8 || mon == 10)) return BAD_DATE; ! /* February gets special check for leapyear */ ! if ((mon == 1) && ((ds.tm_mday > 29) || ! ((ds.tm_mday == 29) && ((ds.tm_year & 3) || ! (((ds.tm_year % 100) == 0) && (((ds.tm_year % 400) != 100))))))) return BAD_DATE; ds.tm_mon = mon;