From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6848 invoked by alias); 20 Jul 2007 16:23:23 -0000 Received: (qmail 6832 invoked by uid 22791); 20 Jul 2007 16:23:22 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 20 Jul 2007 16:23:09 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id l6KGQbBK024394; Fri, 20 Jul 2007 18:26:37 +0200 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id l6KGQbvw024393; Fri, 20 Jul 2007 18:26:37 +0200 Date: Fri, 20 Jul 2007 16:23:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] strptime recursive fixes Message-ID: <20070720162636.GC4603@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2007-07/txt/msg00037.txt.bz2 Hi! This patch fixes recursive strptime invocations, so that 1) nothing is altered if the recursive invocation fails 2) only parsing is done in recursive invocations, they don't recompute any fields 3) all the state changes (have_*, want_*, is_pm, century, ...) from recursive invocations are propagated back to the caller 4) the outermost __strptime_internal at the end recomputes all fields that are needed from the state and struct tm changes gathered from the whole parsing. 2007-07-20 Jakub Jelinek * include/time.h (enum ptime_locale_status): Remove. (__strptime_internal): Remove decided and era_cnt arguments, add statep argument. * time/strptime_l.c (__strptime_internal): Remove decided and era_cnt arguments, add statep argument. Don't recompute any fields in recursive calls, only update caller's tm and state, if recursive call fails, don't change tm nor any state. (get_alt_number): Adjust. (recursive): Adjust caller. (strptime): Likewise. * time/strptime.c (strptime): Likewise. --- libc/include/time.h.jj 2006-07-31 07:57:52.000000000 +0200 +++ libc/include/time.h 2007-07-20 16:51:56.000000000 +0200 @@ -93,17 +93,10 @@ extern int __getclktck (void); /* strptime support. */ -/* Status of lookup: do we use the locale data or the raw data? */ -#ifndef __cplusplus -/* C++ cannot deal with using 'not'. */ -enum ptime_locale_status { not, loc, raw }; - extern char * __strptime_internal (const char *rp, const char *fmt, - struct tm *tm, - enum ptime_locale_status *decided, - int era_cnt, __locale_t locparam) + struct tm *tm, void *statep, + __locale_t locparam) internal_function; -#endif extern double __difftime (time_t time1, time_t time0); --- libc/time/strptime_l.c.jj 2007-07-19 19:46:49.000000000 +0200 +++ libc/time/strptime_l.c 2007-07-20 16:55:44.000000000 +0200 @@ -98,12 +98,12 @@ localtime_r (t, tp) ({ \ __label__ do_normal; \ \ - if (*decided != raw) \ + if (s.decided != raw) \ { \ val = _nl_parse_alt_digit (&rp HELPER_LOCALE_ARG); \ - if (val == -1 && *decided != loc) \ + if (val == -1 && s.decided != loc) \ { \ - *decided = loc; \ + s.decided = loc; \ goto do_normal; \ } \ if (val < from || val > to) \ @@ -123,8 +123,7 @@ localtime_r (t, tp) #endif #define recursive(new_fmt) \ (*(new_fmt) != '\0' \ - && (rp = __strptime_internal (rp, (new_fmt), tm, \ - decided, era_cnt LOCALE_ARG)) != NULL) + && (rp = __strptime_internal (rp, (new_fmt), tm, &s LOCALE_ARG)) != NULL) #ifdef _LIBC @@ -244,19 +243,18 @@ day_of_the_year (struct tm *tm) + (tm->tm_mday - 1)); } #ifdef _LIBC char * internal_function #else static char * #endif -__strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM) +__strptime_internal (rp, fmt, tmp, statep LOCALE_PARAM) const char *rp; const char *fmt; - struct tm *tm; - enum ptime_locale_status *decided; - int era_cnt; + struct tm *tmp; + void *statep; LOCALE_PARAM_DECL { #ifdef _LIBC @@ -268,32 +265,48 @@ __strptime_internal (rp, fmt, tm, decide int cnt; int cnt_longest; size_t val; - int have_I; - int is_pm; - int century; - int want_century; - int want_era; - int have_wday; - int want_xday; - int have_yday; - int have_mon; - int have_mday; - int have_uweek; - int have_wweek; - int week_no; size_t num_eras; - struct era_entry *era; - enum ptime_locale_status decided_longest; - - have_I = is_pm = 0; - century = -1; - want_century = 0; - want_era = 0; - era = NULL; - week_no = 0; + struct era_entry *era = NULL; + enum ptime_locale_status { not, loc, raw } decided_longest; + struct __strptime_state + { + unsigned int have_I : 1; + unsigned int have_wday : 1; + unsigned int have_yday : 1; + unsigned int have_mon : 1; + unsigned int have_mday : 1; + unsigned int have_uweek : 1; + unsigned int have_wweek : 1; + unsigned int is_pm : 1; + unsigned int want_century : 1; + unsigned int want_era : 1; + unsigned int want_xday : 1; + enum ptime_locale_status decided : 2; + signed char week_no; + signed char century; + int era_cnt; + } s; + struct tm tmb; + struct tm *tm; - have_wday = want_xday = have_yday = have_mon = have_mday = have_uweek = 0; - have_wweek = 0; + if (statep == NULL) + { + memset (&s, 0, sizeof (s)); + s.century = -1; + s.era_cnt = -1; +#ifdef _NL_CURRENT + s.decided = not; +#else + s.decided = raw; +#endif + tm = tmp; + } + else + { + s = *(struct __strptime_state *) statep; + tmb = *tmp; + tm = &tmb; + } while (*fmt != '\0') { @@ -334,13 +347,13 @@ __strptime_internal (rp, fmt, tm, decide case 'A': /* Match day of week. */ rp_longest = NULL; - decided_longest = *decided; + decided_longest = s.decided; cnt_longest = -1; for (cnt = 0; cnt < 7; ++cnt) { const char *trp; #ifdef _NL_CURRENT - if (*decided !=raw) + if (s.decided !=raw) { trp = rp; if (match_string (_NL_CURRENT (LC_TIME, DAY_1 + cnt), trp) @@ -348,7 +361,7 @@ __strptime_internal (rp, fmt, tm, decide { rp_longest = trp; cnt_longest = cnt; - if (*decided == not + if (s.decided == not && strcmp (_NL_CURRENT (LC_TIME, DAY_1 + cnt), weekday_name[cnt])) decided_longest = loc; @@ -359,14 +372,14 @@ __strptime_internal (rp, fmt, tm, decide { rp_longest = trp; cnt_longest = cnt; - if (*decided == not + if (s.decided == not && strcmp (_NL_CURRENT (LC_TIME, ABDAY_1 + cnt), ab_weekday_name[cnt])) decided_longest = loc; } } #endif - if (*decided != loc + if (s.decided != loc && (((trp = rp, match_string (weekday_name[cnt], trp)) && trp > rp_longest) || ((trp = rp, match_string (ab_weekday_name[cnt], rp)) @@ -381,22 +394,22 @@ __strptime_internal (rp, fmt, tm, decide /* Does not match a weekday name. */ return NULL; rp = rp_longest; - *decided = decided_longest; + s.decided = decided_longest; tm->tm_wday = cnt_longest; - have_wday = 1; + s.have_wday = 1; break; case 'b': case 'B': case 'h': /* Match month name. */ rp_longest = NULL; - decided_longest = *decided; + decided_longest = s.decided; cnt_longest = -1; for (cnt = 0; cnt < 12; ++cnt) { const char *trp; #ifdef _NL_CURRENT - if (*decided !=raw) + if (s.decided !=raw) { trp = rp; if (match_string (_NL_CURRENT (LC_TIME, MON_1 + cnt), trp) @@ -404,7 +417,7 @@ __strptime_internal (rp, fmt, tm, decide { rp_longest = trp; cnt_longest = cnt; - if (*decided == not + if (s.decided == not && strcmp (_NL_CURRENT (LC_TIME, MON_1 + cnt), month_name[cnt])) decided_longest = loc; @@ -415,14 +428,14 @@ __strptime_internal (rp, fmt, tm, decide { rp_longest = trp; cnt_longest = cnt; - if (*decided == not + if (s.decided == not && strcmp (_NL_CURRENT (LC_TIME, ABMON_1 + cnt), ab_month_name[cnt])) decided_longest = loc; } } #endif - if (*decided != loc + if (s.decided != loc && (((trp = rp, match_string (month_name[cnt], trp)) && trp > rp_longest) || ((trp = rp, match_string (ab_month_name[cnt], trp)) @@ -437,78 +450,78 @@ __strptime_internal (rp, fmt, tm, decide /* Does not match a month name. */ return NULL; rp = rp_longest; - *decided = decided_longest; + s.decided = decided_longest; tm->tm_mon = cnt_longest; - have_mon = 1; - want_xday = 1; + s.have_mon = 1; + s.want_xday = 1; break; case 'c': /* Match locale's date and time format. */ #ifdef _NL_CURRENT - if (*decided != raw) + if (s.decided != raw) { if (!recursive (_NL_CURRENT (LC_TIME, D_T_FMT))) { - if (*decided == loc) + if (s.decided == loc) return NULL; else rp = rp_backup; } else { - if (*decided == not && + if (s.decided == not && strcmp (_NL_CURRENT (LC_TIME, D_T_FMT), HERE_D_T_FMT)) - *decided = loc; - want_xday = 1; + s.decided = loc; + s.want_xday = 1; break; } - *decided = raw; + s.decided = raw; } #endif if (!recursive (HERE_D_T_FMT)) return NULL; - want_xday = 1; + s.want_xday = 1; break; case 'C': /* Match century number. */ match_century: get_number (0, 99, 2); - century = val; - want_xday = 1; + s.century = val; + s.want_xday = 1; break; case 'd': case 'e': /* Match day of month. */ get_number (1, 31, 2); tm->tm_mday = val; - have_mday = 1; - want_xday = 1; + s.have_mday = 1; + s.want_xday = 1; break; case 'F': if (!recursive ("%Y-%m-%d")) return NULL; - want_xday = 1; + s.want_xday = 1; break; case 'x': #ifdef _NL_CURRENT - if (*decided != raw) + if (s.decided != raw) { if (!recursive (_NL_CURRENT (LC_TIME, D_FMT))) { - if (*decided == loc) + if (s.decided == loc) return NULL; else rp = rp_backup; } else { - if (*decided == not + if (s.decided == not && strcmp (_NL_CURRENT (LC_TIME, D_FMT), HERE_D_FMT)) - *decided = loc; - want_xday = 1; + s.decided = loc; + s.want_xday = 1; break; } - *decided = raw; + s.decided = raw; } #endif /* Fall through. */ @@ -516,14 +529,14 @@ __strptime_internal (rp, fmt, tm, decide /* Match standard day format. */ if (!recursive (HERE_D_FMT)) return NULL; - want_xday = 1; + s.want_xday = 1; break; case 'k': case 'H': /* Match hour in 24-hour clock. */ get_number (0, 23, 2); tm->tm_hour = val; - have_I = 0; + s.have_I = 0; break; case 'l': /* Match hour in 12-hour clock. GNU extension. */ @@ -531,20 +544,20 @@ __strptime_internal (rp, fmt, tm, decide /* Match hour in 12-hour clock. */ get_number (1, 12, 2); tm->tm_hour = val % 12; - have_I = 1; + s.have_I = 1; break; case 'j': /* Match day number of year. */ get_number (1, 366, 3); tm->tm_yday = val - 1; - have_yday = 1; + s.have_yday = 1; break; case 'm': /* Match number of month. */ get_number (1, 12, 2); tm->tm_mon = val - 1; - have_mon = 1; - want_xday = 1; + s.have_mon = 1; + s.want_xday = 1; break; case 'M': /* Match minute. */ @@ -560,52 +573,55 @@ __strptime_internal (rp, fmt, tm, decide case 'p': /* Match locale's equivalent of AM/PM. */ #ifdef _NL_CURRENT - if (*decided != raw) + if (s.decided != raw) { if (match_string (_NL_CURRENT (LC_TIME, AM_STR), rp)) { if (strcmp (_NL_CURRENT (LC_TIME, AM_STR), HERE_AM_STR)) - *decided = loc; + s.decided = loc; + s.is_pm = 0; break; } if (match_string (_NL_CURRENT (LC_TIME, PM_STR), rp)) { if (strcmp (_NL_CURRENT (LC_TIME, PM_STR), HERE_PM_STR)) - *decided = loc; - is_pm = 1; + s.decided = loc; + s.is_pm = 1; break; } - *decided = raw; + s.decided = raw; } #endif if (!match_string (HERE_AM_STR, rp)) { if (match_string (HERE_PM_STR, rp)) - is_pm = 1; + s.is_pm = 1; else return NULL; } + else + s.is_pm = 0; break; case 'r': #ifdef _NL_CURRENT - if (*decided != raw) + if (s.decided != raw) { if (!recursive (_NL_CURRENT (LC_TIME, T_FMT_AMPM))) { - if (*decided == loc) + if (s.decided == loc) return NULL; else rp = rp_backup; } else { - if (*decided == not && + if (s.decided == not && strcmp (_NL_CURRENT (LC_TIME, T_FMT_AMPM), HERE_T_FMT_AMPM)) - *decided = loc; + s.decided = loc; break; } - *decided = raw; + s.decided = raw; } #endif if (!recursive (HERE_T_FMT_AMPM)) @@ -644,11 +660,11 @@ __strptime_internal (rp, fmt, tm, decide break; case 'X': #ifdef _NL_CURRENT - if (*decided != raw) + if (s.decided != raw) { if (!recursive (_NL_CURRENT (LC_TIME, T_FMT))) { - if (*decided == loc) + if (s.decided == loc) return NULL; else rp = rp_backup; @@ -656,10 +672,10 @@ __strptime_internal (rp, fmt, tm, decide else { if (strcmp (_NL_CURRENT (LC_TIME, T_FMT), HERE_T_FMT)) - *decided = loc; + s.decided = loc; break; } - *decided = raw; + s.decided = raw; } #endif /* Fall through. */ @@ -670,7 +686,7 @@ __strptime_internal (rp, fmt, tm, decide case 'u': get_number (1, 7, 1); tm->tm_wday = val % 7; - have_wday = 1; + s.have_wday = 1; break; case 'g': get_number (0, 99, 2); @@ -687,13 +703,13 @@ __strptime_internal (rp, fmt, tm, decide break; case 'U': get_number (0, 53, 2); - week_no = val; - have_uweek = 1; + s.week_no = val; + s.have_uweek = 1; break; case 'W': get_number (0, 53, 2); - week_no = val; - have_wweek = 1; + s.week_no = val; + s.have_wweek = 1; break; case 'V': get_number (0, 53, 2); @@ -704,7 +720,7 @@ __strptime_internal (rp, fmt, tm, decide /* Match number of weekday. */ get_number (0, 6, 1); tm->tm_wday = val; - have_wday = 1; + s.have_wday = 1; break; case 'y': match_year_in_century: @@ -714,15 +730,15 @@ __strptime_internal (rp, fmt, tm, decide values in the range 69-99 refer to the twentieth century. */ tm->tm_year = val >= 69 ? val : val + 100; /* Indicate that we want to use the century, if specified. */ - want_century = 1; - want_xday = 1; + s.want_century = 1; + s.want_xday = 1; break; case 'Y': /* Match year including century number. */ get_number (0, 9999, 4); tm->tm_year = val - 1900; - want_century = 0; - want_xday = 1; + s.want_century = 0; + s.want_xday = 1; break; case 'Z': /* XXX How to handle this? */ @@ -769,7 +785,7 @@ __strptime_internal (rp, fmt, tm, decide { case 'c': /* Match locale's alternate date and time format. */ - if (*decided != raw) + if (s.decided != raw) { const char *fmt = _NL_CURRENT (LC_TIME, ERA_D_T_FMT); @@ -778,7 +794,7 @@ __strptime_internal (rp, fmt, tm, decide if (!recursive (fmt)) { - if (*decided == loc) + if (s.decided == loc) return NULL; else rp = rp_backup; @@ -786,27 +802,27 @@ __strptime_internal (rp, fmt, tm, decide else { if (strcmp (fmt, HERE_D_T_FMT)) - *decided = loc; - want_xday = 1; + s.decided = loc; + s.want_xday = 1; break; } - *decided = raw; + s.decided = raw; } /* The C locale has no era information, so use the normal representation. */ if (!recursive (HERE_D_T_FMT)) return NULL; - want_xday = 1; + s.want_xday = 1; break; case 'C': - if (*decided != raw) + if (s.decided != raw) { - if (era_cnt >= 0) + if (s.era_cnt >= 0) { - era = _nl_select_era_entry (era_cnt HELPER_LOCALE_ARG); + era = _nl_select_era_entry (s.era_cnt HELPER_LOCALE_ARG); if (era != NULL && match_string (era->era_name, rp)) { - *decided = loc; + s.decided = loc; break; } else @@ -815,43 +831,43 @@ __strptime_internal (rp, fmt, tm, decide num_eras = _NL_CURRENT_WORD (LC_TIME, _NL_TIME_ERA_NUM_ENTRIES); - for (era_cnt = 0; era_cnt < (int) num_eras; - ++era_cnt, rp = rp_backup) + for (s.era_cnt = 0; s.era_cnt < (int) num_eras; + ++s.era_cnt, rp = rp_backup) { - era = _nl_select_era_entry (era_cnt + era = _nl_select_era_entry (s.era_cnt HELPER_LOCALE_ARG); if (era != NULL && match_string (era->era_name, rp)) { - *decided = loc; + s.decided = loc; break; } } - if (era_cnt != (int) num_eras) + if (s.era_cnt != (int) num_eras) break; - era_cnt = -1; - if (*decided == loc) + s.era_cnt = -1; + if (s.decided == loc) return NULL; - *decided = raw; + s.decided = raw; } /* The C locale has no era information, so use the normal representation. */ goto match_century; case 'y': - if (*decided != raw) + if (s.decided != raw) { get_number(0, 9999, 4); tm->tm_year = val; - want_era = 1; - want_xday = 1; - want_century = 1; + s.want_era = 1; + s.want_xday = 1; + s.want_century = 1; - if (era_cnt >= 0) + if (s.era_cnt >= 0) { - assert (*decided == loc); + assert (s.decided == loc); - era = _nl_select_era_entry (era_cnt HELPER_LOCALE_ARG); + era = _nl_select_era_entry (s.era_cnt HELPER_LOCALE_ARG); bool match = false; if (era != NULL) { @@ -870,9 +886,9 @@ __strptime_internal (rp, fmt, tm, decide num_eras = _NL_CURRENT_WORD (LC_TIME, _NL_TIME_ERA_NUM_ENTRIES); - for (era_cnt = 0; era_cnt < (int) num_eras; ++era_cnt) + for (s.era_cnt = 0; s.era_cnt < (int) num_eras; ++s.era_cnt) { - era = _nl_select_era_entry (era_cnt + era = _nl_select_era_entry (s.era_cnt HELPER_LOCALE_ARG); if (era != NULL) { @@ -883,58 +899,58 @@ __strptime_internal (rp, fmt, tm, decide - (int64_t) era->start_date[0]) * era->absolute_direction)) { - *decided = loc; + s.decided = loc; break; } } } - if (era_cnt != (int) num_eras) + if (s.era_cnt != (int) num_eras) break; - era_cnt = -1; - if (*decided == loc) + s.era_cnt = -1; + if (s.decided == loc) return NULL; - *decided = raw; + s.decided = raw; } goto match_year_in_century; case 'Y': - if (*decided != raw) + if (s.decided != raw) { num_eras = _NL_CURRENT_WORD (LC_TIME, _NL_TIME_ERA_NUM_ENTRIES); - for (era_cnt = 0; era_cnt < (int) num_eras; - ++era_cnt, rp = rp_backup) + for (s.era_cnt = 0; s.era_cnt < (int) num_eras; + ++s.era_cnt, rp = rp_backup) { - era = _nl_select_era_entry (era_cnt HELPER_LOCALE_ARG); + era = _nl_select_era_entry (s.era_cnt HELPER_LOCALE_ARG); if (era != NULL && recursive (era->era_format)) break; } - if (era_cnt == (int) num_eras) + if (s.era_cnt == (int) num_eras) { - era_cnt = -1; - if (*decided == loc) + s.era_cnt = -1; + if (s.decided == loc) return NULL; else rp = rp_backup; } else { - *decided = loc; - era_cnt = -1; + s.decided = loc; + s.era_cnt = -1; break; } - *decided = raw; + s.decided = raw; } get_number (0, 9999, 4); tm->tm_year = val - 1900; - want_century = 0; - want_xday = 1; + s.want_century = 0; + s.want_xday = 1; break; case 'x': - if (*decided != raw) + if (s.decided != raw) { const char *fmt = _NL_CURRENT (LC_TIME, ERA_D_FMT); @@ -943,7 +959,7 @@ __strptime_internal (rp, fmt, tm, decide if (!recursive (fmt)) { - if (*decided == loc) + if (s.decided == loc) return NULL; else rp = rp_backup; @@ -951,16 +967,16 @@ __strptime_internal (rp, fmt, tm, decide else { if (strcmp (fmt, HERE_D_FMT)) - *decided = loc; + s.decided = loc; break; } - *decided = raw; + s.decided = raw; } if (!recursive (HERE_D_FMT)) return NULL; break; case 'X': - if (*decided != raw) + if (s.decided != raw) { const char *fmt = _NL_CURRENT (LC_TIME, ERA_T_FMT); @@ -969,7 +985,7 @@ __strptime_internal (rp, fmt, tm, decide if (!recursive (fmt)) { - if (*decided == loc) + if (s.decided == loc) return NULL; else rp = rp_backup; @@ -977,10 +993,10 @@ __strptime_internal (rp, fmt, tm, decide else { if (strcmp (fmt, HERE_T_FMT)) - *decided = loc; + s.decided = loc; break; } - *decided = raw; + s.decided = raw; } if (!recursive (HERE_T_FMT)) return NULL; @@ -1007,29 +1023,29 @@ __strptime_internal (rp, fmt, tm, decide /* Match day of month using alternate numeric symbols. */ get_alt_number (1, 31, 2); tm->tm_mday = val; - have_mday = 1; - want_xday = 1; + s.have_mday = 1; + s.want_xday = 1; break; case 'H': /* Match hour in 24-hour clock using alternate numeric symbols. */ get_alt_number (0, 23, 2); tm->tm_hour = val; - have_I = 0; + s.have_I = 0; break; case 'I': /* Match hour in 12-hour clock using alternate numeric symbols. */ get_alt_number (1, 12, 2); tm->tm_hour = val % 12; - have_I = 1; + s.have_I = 1; break; case 'm': /* Match month using alternate numeric symbols. */ get_alt_number (1, 12, 2); tm->tm_mon = val - 1; - have_mon = 1; - want_xday = 1; + s.have_mon = 1; + s.want_xday = 1; break; case 'M': /* Match minutes using alternate numeric symbols. */ @@ -1043,13 +1059,13 @@ __strptime_internal (rp, fmt, tm, decide break; case 'U': get_alt_number (0, 53, 2); - week_no = val; - have_uweek = 1; + s.week_no = val; + s.have_uweek = 1; break; case 'W': get_alt_number (0, 53, 2); - week_no = val; - have_wweek = 1; + s.week_no = val; + s.have_wweek = 1; break; case 'V': get_alt_number (0, 53, 2); @@ -1060,13 +1076,13 @@ __strptime_internal (rp, fmt, tm, decide /* Match number of weekday using alternate numeric symbols. */ get_alt_number (0, 6, 1); tm->tm_wday = val; - have_wday = 1; + s.have_wday = 1; break; case 'y': /* Match year within century using alternate numeric symbols. */ get_alt_number (0, 99, 2); tm->tm_year = val >= 69 ? val : val + 100; - want_xday = 1; + s.want_xday = 1; break; default: return NULL; @@ -1077,24 +1093,33 @@ __strptime_internal (rp, fmt, tm, decide } } - if (have_I && is_pm) + if (statep != NULL) + { + /* Recursive invocation, returning success, so + update parent's struct tm and state. */ + *(struct __strptime_state *) statep = s; + *tmp = tmb; + return (char *) rp; + } + + if (s.have_I && s.is_pm) tm->tm_hour += 12; - if (century != -1) + if (s.century != -1) { - if (want_century) - tm->tm_year = tm->tm_year % 100 + (century - 19) * 100; + if (s.want_century) + tm->tm_year = tm->tm_year % 100 + (s.century - 19) * 100; else /* Only the century, but not the year. Strange, but so be it. */ - tm->tm_year = (century - 19) * 100; + tm->tm_year = (s.century - 19) * 100; } - if (era_cnt != -1) + if (s.era_cnt != -1) { - era = _nl_select_era_entry (era_cnt HELPER_LOCALE_ARG); + era = _nl_select_era_entry (s.era_cnt HELPER_LOCALE_ARG); if (era == NULL) return NULL; - if (want_era) + if (s.want_era) tm->tm_year = (era->start_date[0] + ((tm->tm_year - era->offset) * era->absolute_direction)); @@ -1103,68 +1128,68 @@ __strptime_internal (rp, fmt, tm, decide tm->tm_year = era->start_date[0]; } else - if (want_era) + if (s.want_era) { /* No era found but we have seen an E modifier. Rectify some values. */ - if (want_century && century == -1 && tm->tm_year < 69) + if (s.want_century && s.century == -1 && tm->tm_year < 69) tm->tm_year += 100; } - if (want_xday && !have_wday) + if (s.want_xday && !s.have_wday) { - if ( !(have_mon && have_mday) && have_yday) + if ( !(s.have_mon && s.have_mday) && s.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) + if (!s.have_mon) tm->tm_mon = t_mon - 1; - if (!have_mday) + if (!s.have_mday) tm->tm_mday = (tm->tm_yday - __mon_yday[__isleap(1900 + tm->tm_year)][t_mon - 1] + 1); - have_mon = 1; - have_mday = 1; + s.have_mon = 1; + s.have_mday = 1; } /* Don't crash in day_of_the_week if tm_mon is uninitialized. */ - if (have_mon || (unsigned) tm->tm_mon <= 11) + if (s.have_mon || (unsigned) tm->tm_mon <= 11) day_of_the_week (tm); } - if (want_xday && !have_yday && (have_mon || (unsigned) tm->tm_mon <= 11)) + if (s.want_xday && !s.have_yday && (s.have_mon || (unsigned) tm->tm_mon <= 11)) day_of_the_year (tm); - if ((have_uweek || have_wweek) && have_wday) + if ((s.have_uweek || s.have_wweek) && s.have_wday) { int save_wday = tm->tm_wday; int save_mday = tm->tm_mday; int save_mon = tm->tm_mon; - int w_offset = have_uweek ? 0 : 1; + int w_offset = s.have_uweek ? 0 : 1; tm->tm_mday = 1; tm->tm_mon = 0; day_of_the_week (tm); - if (have_mday) + if (s.have_mday) tm->tm_mday = save_mday; - if (have_mon) + if (s.have_mon) tm->tm_mon = save_mon; - if (!have_yday) + if (!s.have_yday) tm->tm_yday = ((7 - (tm->tm_wday - w_offset)) % 7 - + (week_no - 1) *7 + + (s.week_no - 1) *7 + save_wday - w_offset); - if (!have_mday || !have_mon) + if (!s.have_mday || !s.have_mon) { int t_mon = 0; while (__mon_yday[__isleap(1900 + tm->tm_year)][t_mon] <= tm->tm_yday) t_mon++; - if (!have_mon) + if (!s.have_mon) tm->tm_mon = t_mon - 1; - if (!have_mday) + if (!s.have_mday) tm->tm_mday = (tm->tm_yday - __mon_yday[__isleap(1900 + tm->tm_year)][t_mon - 1] + 1); @@ -1184,14 +1209,7 @@ strptime (buf, format, tm LOCALE_PARAM) struct tm *tm; LOCALE_PARAM_DECL { - enum ptime_locale_status decided; - -#ifdef _NL_CURRENT - decided = not; -#else - decided = raw; -#endif - return __strptime_internal (buf, format, tm, &decided, -1 LOCALE_ARG); + return __strptime_internal (buf, format, tm, NULL LOCALE_ARG); } #ifdef _LIBC --- libc/time/strptime.c.jj 2004-03-14 22:03:21.000000000 +0100 +++ libc/time/strptime.c 2007-07-20 16:37:29.000000000 +0200 @@ -1,5 +1,6 @@ /* Convert a string representation of time to a time value. - Copyright (C) 1996-2000, 2001, 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 1996-2000, 2001, 2002, 2004, 2007 + Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 1996. @@ -33,8 +34,6 @@ strptime (buf, format, tm) const char *format; struct tm *tm; { - enum ptime_locale_status decided = not; - return __strptime_internal (buf, format, tm, &decided, -1, - _NL_CURRENT_LOCALE); + return __strptime_internal (buf, format, tm, NULL, _NL_CURRENT_LOCALE); } libc_hidden_def (strptime) Jakub