]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - time/strptime_l.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / time / strptime_l.c
index 27b6f9ba868799ee9e103552ca74e71c15792620..d8aed0d5f60e495294537f2fb4e632ff5a42f31d 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2004, 2005, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 2002-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -12,9 +12,8 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #include <stdbool.h>
 
 #ifdef _LIBC
+# define HAVE_LOCALTIME_R 0
 # include "../locale/localeinfo.h"
 #endif
 
 
-#ifndef __P
-# if defined __GNUC__ || (defined __STDC__ && __STDC__)
-#  define __P(args) args
-# else
-#  define __P(args) ()
-# endif  /* GCC.  */
-#endif  /* Not __P.  */
-
-
 #if ! HAVE_LOCALTIME_R && ! defined localtime_r
 # ifdef _LIBC
 #  define localtime_r __localtime_r
 # else
 /* Approximate localtime_r as best we can in its absence.  */
 #  define localtime_r my_localtime_r
-static struct tm *localtime_r __P ((const time_t *, struct tm *));
+static struct tm *localtime_r (const time_t *, struct tm *);
 static struct tm *
-localtime_r (t, tp)
-     const time_t *t;
-     struct tm *tp;
+localtime_r (const time_t *t, struct tm *tp)
 {
   struct tm *l = localtime (t);
   if (! l)
@@ -82,7 +71,7 @@ localtime_r (t, tp)
   do {                                                                       \
     int __n = n;                                                             \
     val = 0;                                                                 \
-    while (*rp == ' ')                                                       \
+    while (ISSPACE (*rp))                                                    \
       ++rp;                                                                  \
     if (*rp < '0' || *rp > '9')                                                      \
       return NULL;                                                           \
@@ -98,12 +87,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,19 +112,22 @@ 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
 /* This is defined in locale/C-time.c in the GNU libc.  */
-extern const struct locale_data _nl_C_LC_TIME attribute_hidden;
+extern const struct __locale_data _nl_C_LC_TIME attribute_hidden;
 
 # define weekday_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (DAY_1)].string)
 # define ab_weekday_name \
   (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABDAY_1)].string)
 # define month_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (MON_1)].string)
 # define ab_month_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABMON_1)].string)
+# define alt_month_name \
+  (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ALTMON_1)].string)
+# define ab_alt_month_name \
+  (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (_NL_ABALTMON_1)].string)
 # define HERE_D_T_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (D_T_FMT)].string)
 # define HERE_D_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (D_FMT)].string)
 # define HERE_AM_STR (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (AM_STR)].string)
@@ -193,17 +185,13 @@ static const unsigned short int __mon_yday[2][13] =
 # undef _NL_CURRENT_WORD
 # define _NL_CURRENT_WORD(category, item) \
   (current->values[_NL_ITEM_INDEX (item)].word)
-# define LOCALE_PARAM , locale
+# define LOCALE_PARAM , locale_t locale
 # define LOCALE_ARG , locale
-# define LOCALE_PARAM_PROTO , __locale_t locale
-# define LOCALE_PARAM_DECL __locale_t locale;
 # define HELPER_LOCALE_ARG , current
 # define ISSPACE(Ch) __isspace_l (Ch, locale)
 #else
 # define LOCALE_PARAM
 # define LOCALE_ARG
-# define LOCALE_PARAM_DECL
-# define LOCALE_PARAM_PROTO
 # define HELPER_LOCALE_ARG
 # define ISSPACE(Ch) isspace (Ch)
 #endif
@@ -223,7 +211,7 @@ static void
 day_of_the_week (struct tm *tm)
 {
   /* We know that January 1st 1970 was a Thursday (= 4).  Compute the
-     the difference between this data in the one on TM and so determine
+     difference between this data in the one on TM and so determine
      the weekday.  */
   int corr_year = 1900 + tm->tm_year - (tm->tm_mon < 2);
   int wday = (-473
@@ -247,20 +235,14 @@ day_of_the_year (struct tm *tm)
 
 #ifdef _LIBC
 char *
-internal_function
 #else
 static char *
 #endif
-__strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
-     const char *rp;
-     const char *fmt;
-     struct tm *tm;
-     enum ptime_locale_status *decided;
-     int era_cnt;
-     LOCALE_PARAM_DECL
+__strptime_internal (const char *rp, const char *fmt, struct tm *tmp,
+                    void *statep LOCALE_PARAM)
 {
 #ifdef _LIBC
-  struct locale_data *const current = locale->__locales[LC_TIME];
+  struct __locale_data *const current = locale->__locales[LC_TIME];
 #endif
 
   const char *rp_backup;
@@ -268,32 +250,48 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
   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;
-
-  have_wday = want_xday = have_yday = have_mon = have_mday = have_uweek = 0;
-  have_wweek = 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;
+
+  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')
     {
@@ -316,10 +314,18 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
        }
 
       ++fmt;
-#ifndef _NL_CURRENT
-      /* We need this for handling the `E' modifier.  */
+      /* We discard strftime modifiers.  */
+      while (*fmt == '-' || *fmt == '_' || *fmt == '0'
+            || *fmt == '^' || *fmt == '#')
+       ++fmt;
+
+      /* And field width.  */
+      while (*fmt >= '0' && *fmt <= '9')
+       ++fmt;
+
+      /* In some cases, modifiers are handled by adjusting state and
+         then restarting the switch statement below.  */
     start_over:
-#endif
 
       /* Make back up of current processing pointer.  */
       rp_backup = rp;
@@ -334,13 +340,13 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
        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 +354,7 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
                    {
                      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 +365,14 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
                    {
                      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 +387,22 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
            /* 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 +410,7 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
                    {
                      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,18 +421,51 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
                    {
                      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;
                    }
+#ifdef _LIBC
+                 /* Now check the alt month.  */
+                 trp = rp;
+                 if (match_string (_NL_CURRENT (LC_TIME, ALTMON_1 + cnt), trp)
+                     && trp > rp_longest)
+                   {
+                     rp_longest = trp;
+                     cnt_longest = cnt;
+                     if (s.decided == not
+                         && strcmp (_NL_CURRENT (LC_TIME, ALTMON_1 + cnt),
+                                    alt_month_name[cnt]))
+                       decided_longest = loc;
+                   }
+                 trp = rp;
+                 if (match_string (_NL_CURRENT (LC_TIME, _NL_ABALTMON_1 + cnt),
+                                   trp)
+                     && trp > rp_longest)
+                   {
+                     rp_longest = trp;
+                     cnt_longest = cnt;
+                     if (s.decided == not
+                         && strcmp (_NL_CURRENT (LC_TIME, _NL_ABALTMON_1 + cnt),
+                                    alt_month_name[cnt]))
+                       decided_longest = loc;
+                   }
+#endif
                }
 #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))
-                         && trp > rp_longest)))
+                         && trp > rp_longest)
+#ifdef _LIBC
+                     || ((trp = rp, match_string (alt_month_name[cnt], trp))
+                         && trp > rp_longest)
+                     || ((trp = rp, match_string (ab_alt_month_name[cnt], trp))
+                         && trp > rp_longest)
+#endif
+             ))
                {
                  rp_longest = trp;
                  cnt_longest = cnt;
@@ -437,78 +476,78 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
            /* 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 +555,14 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
          /* 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 +570,20 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
          /* 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 +599,55 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
        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 +686,11 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
          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 +698,10 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
              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 +712,7 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
        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 +729,13 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
          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 +746,7 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
          /* 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,27 +756,39 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
             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?  */
+         /* Read timezone but perform no conversion.  */
+         while (ISSPACE (*rp))
+           rp++;
+         while (!ISSPACE (*rp) && *rp != '\0')
+           rp++;
          break;
        case 'z':
-         /* We recognize two formats: if two digits are given, these
-            specify hours.  If fours digits are used, minutes are
-            also specified.  */
+         /* We recognize four formats:
+            1. Two digits specify hours.
+            2. Four digits specify hours and minutes.
+            3. Two digits, ':', and two digits specify hours and minutes.
+            4. 'Z' is equivalent to +0000.  */
          {
            val = 0;
-           while (*rp == ' ')
+           while (ISSPACE (*rp))
              ++rp;
+           if (*rp == 'Z')
+             {
+               ++rp;
+               tm->tm_gmtoff = 0;
+               break;
+             }
            if (*rp != '+' && *rp != '-')
              return NULL;
            bool neg = *rp++ == '-';
@@ -743,22 +797,18 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
              {
                val = val * 10 + *rp++ - '0';
                ++n;
+               if (*rp == ':' && n == 2 && isdigit (*(rp + 1)))
+                 ++rp;
              }
            if (n == 2)
              val *= 100;
            else if (n != 4)
              /* Only two or four digits recognized.  */
              return NULL;
-           else
-             {
-               /* We have to convert the minutes into decimal.  */
-               if (val % 100 >= 60)
-                 return NULL;
-               val = (val / 100) * 100 + ((val % 100) * 50) / 30;
-             }
-           if (val > 1200)
+           else if (val % 100 >= 60)
+             /* Minutes valid range is 0 through 59.  */
              return NULL;
-           tm->tm_gmtoff = (val * 3600) / 100;
+           tm->tm_gmtoff = (val / 100) * 3600 + (val % 100) * 60;
            if (neg)
              tm->tm_gmtoff = -tm->tm_gmtoff;
          }
@@ -769,7 +819,7 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
            {
            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 +828,7 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
 
                  if (!recursive (fmt))
                    {
-                     if (*decided == loc)
+                     if (s.decided == loc)
                        return NULL;
                      else
                        rp = rp_backup;
@@ -786,27 +836,27 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
                  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 +865,43 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
 
                  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 +920,9 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
 
                  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 +933,57 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
                                           - (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;
                      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 +992,7 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
 
                  if (!recursive (fmt))
                    {
-                     if (*decided == loc)
+                     if (s.decided == loc)
                        return NULL;
                      else
                        rp = rp_backup;
@@ -951,16 +1000,16 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
                  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 +1018,7 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
 
                  if (!recursive (fmt))
                    {
-                     if (*decided == loc)
+                     if (s.decided == loc)
                        return NULL;
                      else
                        rp = rp_backup;
@@ -977,10 +1026,10 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
                  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;
@@ -1002,34 +1051,40 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
        case 'O':
          switch (*fmt++)
            {
+           case 'b':
+           case 'B':
+           case 'h':
+             /* Match month name.  Reprocess as plain 'B'.  */
+             fmt--;
+             goto start_over;
            case 'd':
            case 'e':
              /* 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 +1098,13 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
              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 +1115,13 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
              /* 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 +1132,33 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
        }
     }
 
-  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 +1167,68 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
        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
-                      + save_wday - w_offset);
+                      + (s.week_no - 1) * 7
+                      + (save_wday - w_offset + 7) % 7);
 
-      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);
@@ -1178,20 +1242,9 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM)
 
 
 char *
-strptime (buf, format, tm LOCALE_PARAM)
-     const char *buf;
-     const char *format;
-     struct tm *tm;
-     LOCALE_PARAM_DECL
+strptime (const char *buf, const char *format, struct tm *tm LOCALE_PARAM)
 {
-  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