/* This routine should be rewritten to not require copying the buffer - [ahc] */ static struct tm * parse_date(const char *str, int len) { struct tm *tm; char tmp[TIMEBUFLEN]; char *t; char *wday = NULL; char *day = NULL; char *month = NULL; char *year = NULL; char *time = NULL; char *zone = NULL; int bl = MIN(len, TIMEBUFLEN - 1); memcpy(tmp, str, bl); tmp[bl] = '\0'; for (t = (char *)strtok(tmp, ", "); t; t = (char *)strtok(NULL, ", ")) { if (isdigit(*t)) { if (!day) { day = t; t = strchr(t, '-'); if (t) { *t++ = '\0'; month = t; t = strchr(t, '-'); if (!t) return NULL; *t++ = '\0'; year = t; } } else if (strchr(t, ':')) time = t; else if (!year) year = t; } else if (!wday) wday = t; else if (!month) month = t; else if (!zone) zone = t; } tm = parse_date_elements(day, month, year, time, zone); return tm; }
static struct tm * parse_date(const char *str) { struct tm *tm; char *tmp = xstrdup(str); char *t; char *wday = NULL; char *day = NULL; char *month = NULL; char *year = NULL; char *time = NULL; char *zone = NULL; for (t = strtok(tmp, ", "); t; t = strtok(NULL, ", ")) { if (xisdigit(*t)) { if (!day) { day = t; t = strchr(t, '-'); if (t) { *t++ = '\0'; month = t; t = strchr(t, '-'); if (!t) return NULL; *t++ = '\0'; year = t; } } else if (strchr(t, ':')) time = t; else if (!year) year = t; } else if (!wday) wday = t; else if (!month) month = t; else if (!zone) zone = t; } tm = parse_date_elements(day, month, year, time, zone); xfree(tmp); return tm; }