From: wessels <> Date: Tue, 27 May 1997 08:54:27 +0000 (+0000) Subject: adding X-Git-Tag: SQUID_3_0_PRE1~4967 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59ef7bfceab1f4d7963e1335cbd6525104160d75;p=thirdparty%2Fsquid.git adding --- diff --git a/lib/iso3307.c b/lib/iso3307.c new file mode 100644 index 0000000000..24d373e870 --- /dev/null +++ b/lib/iso3307.c @@ -0,0 +1,50 @@ +#include "config.h" + +#if HAVE_STDIO_H +#include +#endif +#if HAVE_STRING_H +#include +#endif +#if HAVE_CTYPE_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif +#if HAVE_TIME_H +#include +#endif +#if HAVE_SYS_TIME_H +#include +#endif + + +#define ASCII_DIGIT(c) ((c)-48) + +time_t +parse_iso3307_time(const char *buf) +{ +/* buf is an ISO 3307 style time: YYYYMMDDHHMMSS or YYYYMMDDHHMMSS.xxx */ + struct tm tms; + time_t t; + while (*buf == ' ' || *buf == '\t') + buf++; + if ((int) strlen(buf) < 14) + return 0; + memset(&tms, '\0', sizeof(struct tm)); + tms.tm_year = (ASCII_DIGIT(buf[2]) * 10) + ASCII_DIGIT(buf[3]); + tms.tm_mon = (ASCII_DIGIT(buf[4]) * 10) + ASCII_DIGIT(buf[5]) - 1; + tms.tm_mday = (ASCII_DIGIT(buf[6]) * 10) + ASCII_DIGIT(buf[7]); + tms.tm_hour = (ASCII_DIGIT(buf[8]) * 10) + ASCII_DIGIT(buf[9]); + tms.tm_min = (ASCII_DIGIT(buf[10]) * 10) + ASCII_DIGIT(buf[11]); + tms.tm_sec = (ASCII_DIGIT(buf[12]) * 10) + ASCII_DIGIT(buf[13]); +#if HAVE_TIMEGM + t = timegm(&tms); +#elif HAVE_MKTIME + t = mktime(&tms); +#else + t = (time_t) 0; +#endif + return t; +}