(read_filesystem_list): Show automount-related
[gnulib.git] / lib / strftime.c
index aa83516..8c838f7 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
 
    NOTE: The canonical source of this file is maintained with the GNU C
    Library.  Bugs can be reported to bug-glibc@prep.ai.mit.edu.
@@ -139,7 +139,7 @@ extern int __tz_compute __P ((time_t timer, const struct tm *tm));
 # if ! HAVE_LOCALTIME_R
 #  if ! HAVE_TM_GMTOFF
 /* Approximate gmtime_r as best we can in its absence.  */
-#   define gmtime_r my_gmtime_r
+#  define gmtime_r my_gmtime_r
 static struct tm *gmtime_r __P ((const time_t *, struct tm *));
 static struct tm *
 gmtime_r (t, tp)
@@ -230,6 +230,11 @@ static const char spaces[16] = "                ";
 # define TOUPPER(Ch) (islower (Ch) ? toupper (Ch) : (Ch))
 # define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
 #endif
+/* We don't use `isdigit' here since the locale dependent
+   interpretation is not what we want here.  We only need to accept
+   the arabic digits in the ASCII range.  One day there is perhaps a
+   more reliable way to accept other sets of digits.  */
+#define ISDIGIT(Ch) ((unsigned int) (Ch) - '0' <= 9)
 
 static char *memcpy_lowcase __P ((char *dest, const char *src, size_t len));
 
@@ -324,6 +329,31 @@ static char const month_name[][10] =
   };
 #endif
 
+
+#if !defined _LIBC && HAVE_TZNAME && HAVE_TZSET
+  /* Solaris 2.5 tzset sometimes modifies the storage returned by localtime.
+     Work around this bug by copying *tp before it might be munged.  */
+  size_t _strftime_copytm __P ((char *, size_t, const char *,
+                               const struct tm *));
+  size_t
+  strftime (s, maxsize, format, tp)
+      char *s;
+      size_t maxsize;
+      const char *format;
+      const struct tm *tp;
+  {
+    struct tm tmcopy;
+    tmcopy = *tp;
+    return _strftime_copytm (s, maxsize, format, &tmcopy);
+  }
+# ifdef strftime
+#  undef strftime
+# endif
+# define strftime _strftime_copytm
+#endif
+
+
+
 /* Write information from TP into S according to the format
    string FORMAT, writing no more that MAXSIZE characters
    (including the terminating '\0') and returning number of
@@ -488,38 +518,41 @@ strftime (s, maxsize, format, tp)
 
 #endif /* ! DO_MULTIBYTE */
 
-      /* Check for flags that can modify a number format.  */
+      /* Check for flags that can modify a format.  */
+      pad = 0;
       while (1)
        {
          switch (*++f)
            {
+             /* This influences the number formats.  */
            case '_':
            case '-':
            case '0':
              pad = *f;
              continue;
 
+             /* This changes textual output.  */
            case '^':
              to_uppcase = 1;
              continue;
 
            default:
-             pad = 0;
              break;
            }
          break;
        }
 
       /* As a GNU extension we allow to specify the field width.  */
-      if (isdigit (*f))
+      if (ISDIGIT (*f))
        {
          width = 0;
          do
            {
              width *= 10;
              width += *f - '0';
+             ++f;
            }
-         while (isdigit (*++f));
+         while (ISDIGIT (*f));
        }
 
       /* Check for modifiers.  */