diff options
author | Ulrich Drepper <drepper@redhat.com> | 1999-07-01 22:04:01 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1999-07-01 22:04:01 +0000 |
commit | 8d93eb92afa7e829225a0e884cc492e138feb515 (patch) | |
tree | 93b61cd714a3cd51a74638c8e2916bcab6d889ef /time/strptime.c | |
parent | c5f57c58cae865ec63448282295bb078fc935d39 (diff) | |
download | glibc-8d93eb92afa7e829225a0e884cc492e138feb515.tar.gz glibc-8d93eb92afa7e829225a0e884cc492e138feb515.tar.xz glibc-8d93eb92afa7e829225a0e884cc492e138feb515.zip |
Update
1999-07-01 Cristian Gafton <gafton@redhat.com> * time/strptime.c (strptime): Initialize the tm struct first to avoid returning bogus results on incomplete data. (strptime_internal): day_of_the_week() requres bith tm_mon and tm_mday to be initializaed. Computer them first if they are not given. (strptime_internal): (have_mon, have_mday): New variables.
Diffstat (limited to 'time/strptime.c')
-rw-r--r-- | time/strptime.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/time/strptime.c b/time/strptime.c index 26f77ebbdd..14814ce153 100644 --- a/time/strptime.c +++ b/time/strptime.c @@ -252,13 +252,14 @@ strptime_internal (buf, format, tm, decided) int century, want_century; int have_wday, want_xday; int have_yday; - + int have_mon, have_mday; + rp = buf; fmt = format; have_I = is_pm = 0; century = -1; want_century = 0; - have_wday = want_xday = have_yday = 0; + have_wday = want_xday = have_yday = have_mon = have_mday = 0; while (*fmt != '\0') { @@ -407,6 +408,7 @@ strptime_internal (buf, format, tm, decided) /* Match day of month. */ get_number (1, 31); tm->tm_mday = val; + have_mday = 1; want_xday = 1; break; case 'F': @@ -464,6 +466,7 @@ strptime_internal (buf, format, tm, decided) /* Match number of month. */ get_number (1, 12); tm->tm_mon = val - 1; + have_mon = 1; want_xday = 1; break; case 'M': @@ -743,6 +746,7 @@ strptime_internal (buf, format, tm, decided) /* Match day of month using alternate numeric symbols. */ get_alt_number (1, 31); tm->tm_mday = val; + have_mday = 1; want_xday = 1; break; case 'H': @@ -763,6 +767,7 @@ strptime_internal (buf, format, tm, decided) /* Match month using alternate numeric symbols. */ get_alt_number (1, 12); tm->tm_mon = val - 1; + have_mon = 1; want_xday = 1; break; case 'M': @@ -809,8 +814,19 @@ strptime_internal (buf, format, tm, decided) if (want_century && century != -1) tm->tm_year = tm->tm_year % 100 + (century - 19) * 100; - if (want_xday && !have_wday) - day_of_the_week (tm); + if (want_xday && !have_wday) { + if ( !(have_mon && have_mday) && have_yday) { + /* we don't have tm_mon and/or tm_mday, compute them */ + int t_mon = 0; + while (__mon_yday[__isleap(1900 + tm->tm_year)][t_mon] <= tm->tm_yday) + t_mon++; + if (!have_mon) + tm->tm_mon = t_mon - 1; + if (!have_mday) + tm->tm_mday = tm->tm_yday - __mon_yday[__isleap(1900 + tm->tm_year)][t_mon - 1] + 1; + } + day_of_the_week (tm); + } if (want_xday && !have_yday) day_of_the_year (tm); |