]> code.delx.au - gnu-emacs/blobdiff - src/strftime.c
(syms_of_coding): Doc fix for inhibit-eol-conversion.
[gnu-emacs] / src / strftime.c
index 50aed8ac76a90da3d455d7a9fb7d7435db18ba9d..ec6068a3b280db1f4d44dcb9531a212a04dc030a 100644 (file)
@@ -1,7 +1,7 @@
-/* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,94,95,96,97,98 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.
+   Bugs can be reported to bug-glibc@gnu.org.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
 # include <config.h>
 #endif
 
+/* Some hosts need this in order to declare localtime_r properly.  */
+#ifndef _REENTRANT
+# define _REENTRANT 1
+#endif
+
 #ifdef _LIBC
 # define HAVE_LIMITS_H 1
 # define HAVE_MBLEN 1
@@ -184,7 +189,7 @@ localtime_r (t, tp)
   return tp;
 }
 # endif /* ! HAVE_LOCALTIME_R */
-#endif /* ! defined (_LIBC) */
+#endif /* ! defined _LIBC */
 
 
 #if !defined memset && !defined HAVE_MEMSET && !defined _LIBC
@@ -204,7 +209,7 @@ static const char zeroes[16] = /* "0000000000000000" */
     do                                                                       \
       {                                                                              \
        int _this = _len > 16 ? 16 : _len;                                    \
-       (P) = mempcpy ((P), spaces, _this);                                   \
+       (P) = MEMPCPY ((P), spaces, _this);                                   \
        _len -= _this;                                                        \
       }                                                                              \
     while (_len > 0);                                                        \
@@ -217,7 +222,7 @@ static const char zeroes[16] = /* "0000000000000000" */
     do                                                                       \
       {                                                                              \
        int _this = _len > 16 ? 16 : _len;                                    \
-       (P) = mempcpy ((P), zeroes, _this);                                   \
+       (P) = MEMPCPY ((P), zeroes, _this);                                   \
        _len -= _this;                                                        \
       }                                                                              \
     while (_len > 0);                                                        \
@@ -372,14 +377,6 @@ static char const month_name[][10] =
 
 #ifdef emacs
 # define my_strftime emacs_strftime
- /* Emacs 20.2 uses `-Dstrftime=emacs_strftime' when compiling,
-    because that's how strftime used to be configured.
-    Undo this, since it gets in the way of accessing the underlying strftime,
-    which is needed for things like %Ec in Solaris.
-    The following two lines can be removed once Emacs stops compiling with
-    `-Dstrftime=emacs_strftime'.  */
-# undef strftime
-size_t strftime __P ((char *, size_t, const char *, const struct tm *));
 #else
 # define my_strftime strftime
 #endif
@@ -485,7 +482,7 @@ my_strftime (s, maxsize, format, tp)
 
   for (f = format; *f != '\0'; ++f)
     {
-      int pad;                 /* Padding for number ('-', '_', or 0).  */
+      int pad = 0;             /* Padding for number ('-', '_', or 0).  */
       int modifier;            /* Field modifier ('E', 'O', or 0).  */
       int digits;              /* Max digits for numeric format.  */
       int number_value;        /* Numeric value to be printed.  */
@@ -575,7 +572,6 @@ my_strftime (s, maxsize, format, tp)
 #endif /* ! DO_MULTIBYTE */
 
       /* Check for flags that can modify a format.  */
-      pad = 0;
       while (1)
        {
          switch (*++f)
@@ -746,8 +742,9 @@ my_strftime (s, maxsize, format, tp)
              *u++ = modifier;
            *u++ = format_char;
            *u = '\0';
+           ubuf[0] = '\1';
            len = strftime (ubuf, sizeof ubuf, ufmt, tp);
-           if (len == 0)
+           if (len == 0 && ubuf[0] != '\0')
              return 0;
            cpy (len, ubuf);
          }
@@ -1170,14 +1167,14 @@ my_strftime (s, maxsize, format, tp)
                   valid time_t value.  Check whether an error really
                   occurred.  */
                struct tm tm;
-               localtime_r (&lt, &tm);
-
-               if ((ltm.tm_sec ^ tm.tm_sec)
-                   | (ltm.tm_min ^ tm.tm_min)
-                   | (ltm.tm_hour ^ tm.tm_hour)
-                   | (ltm.tm_mday ^ tm.tm_mday)
-                   | (ltm.tm_mon ^ tm.tm_mon)
-                   | (ltm.tm_year ^ tm.tm_year))
+
+               if (! localtime_r (&lt, &tm)
+                   || ((ltm.tm_sec ^ tm.tm_sec)
+                       | (ltm.tm_min ^ tm.tm_min)
+                       | (ltm.tm_hour ^ tm.tm_hour)
+                       | (ltm.tm_mday ^ tm.tm_mday)
+                       | (ltm.tm_mon ^ tm.tm_mon)
+                       | (ltm.tm_year ^ tm.tm_year)))
                  break;
              }