diff --git a/vfs/ChangeLog b/vfs/ChangeLog index 72cea0d34..bca7d7d5d 100644 --- a/vfs/ChangeLog +++ b/vfs/ChangeLog @@ -1,5 +1,9 @@ 2002-12-12 Pavel Roskin + * vfs.c (is_dos_date): Allow 4-digit years. + (vfs_parse_filedate): Don't limit length of the year field for + DOS dates, subtract 1900 if necessary. + * extfs/apt.in: Fix Y2K bug. * extfs/deba.in: Likewise. * extfs/debd.in: Likewise. diff --git a/vfs/vfs.c b/vfs/vfs.c index 4361698cd..338a3ff74 100644 --- a/vfs/vfs.c +++ b/vfs/vfs.c @@ -1325,17 +1325,26 @@ is_num (int idx) return 1; } +/* Return 1 for MM-DD-YY and MM-DD-YYYY */ static int -is_dos_date (char *str) +is_dos_date (const char *str) { + int len; + if (!str) return 0; - if (strlen (str) == 8 && str[2] == str[5] - && strchr ("\\-/", (int) str[2]) != NULL) - return 1; + len = strlen (str); + if (len != 8 && len != 10) + return 0; - return 0; + if (str[2] != str[5]) + return 0; + + if (!strchr ("\\-/", (int) str[2])) + return 0; + + return 1; } static int @@ -1556,24 +1565,22 @@ vfs_parse_filedate (int idx, time_t *t) where Mon is Jan-Dec, DD, MM, YY two digit day, month, year, YYYY four digit year, hh, mm, ss two digit hour, minute or second. */ - /* Here just this special case with MM-DD-YY */ + /* Special case with MM-DD-YY or MM-DD-YYYY */ if (is_dos_date (p)) { p[2] = p[5] = '-'; - if (sscanf (p, "%2d-%2d-%2d", &d[0], &d[1], &d[2]) == 3) { - /* We expect to get: - 1. MM-DD-YY - 2. DD-MM-YY - 3. YY-MM-DD - 4. YY-DD-MM */ + if (sscanf (p, "%2d-%2d-%d", &d[0], &d[1], &d[2]) == 3) { + /* Months are zero based */ + if (d[0] > 0) + d[0]--; - /* Hmm... maybe, next time :) */ - - /* At last, MM-DD-YY */ - d[0]--; /* Months are zerobased */ - /* Y2K madness */ - if (d[2] < 70) - d[2] += 100; + if (d[2] > 1900) { + d[2] -= 1900; + } else { + /* Y2K madness */ + if (d[2] < 70) + d[2] += 100; + } tim.tm_mon = d[0]; tim.tm_mday = d[1];