Fix autoreconf invocation.
[gnulib.git] / lib / strftime.c
index 78a963b..b68b4cf 100644 (file)
@@ -16,7 +16,7 @@
 
    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation,
-   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
@@ -120,7 +120,7 @@ extern char *tzname[];
    ? (a) >> (b)                \
    : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0))
 
-/* Bound on length of the string representing an integer value or type T.
+/* Bound on length of the string representing an integer type or expression T.
    Subtract 1 for the sign bit if t is signed; log10 (2.0) < 146/485;
    add 1 for integer division truncation; add 1 more for a minus sign
    if needed.  */
@@ -373,20 +373,13 @@ static CHAR_T const month_name[][10] =
 # define ns 0
 #endif
 
-#if ! defined _LIBC && ! HAVE_RUN_TZSET_TEST
-/* Solaris 2.5.x and 2.6 tzset sometimes modify the storage returned
-   by localtime.  On such systems, we must use the tzset and localtime
-   wrappers to work around the bug.  */
-"you must run the autoconf test for a working tzset function"
-#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
    characters written.  If S is NULL, nothing will be written
    anywhere, so to determine how many characters would be
-   written, use NULL for S and (size_t) UINT_MAX for MAXSIZE.  */
+   written, use NULL for S and (size_t) -1 for MAXSIZE.  */
 size_t
 my_strftime (CHAR_T *s, size_t maxsize, const CHAR_T *format,
             const struct tm *tp extra_args_spec LOCALE_PARAM_PROTO)
@@ -439,6 +432,15 @@ my_strftime (CHAR_T *s, size_t maxsize, const CHAR_T *format,
   const char *format_end = NULL;
 #endif
 
+#if ! defined _LIBC && ! HAVE_RUN_TZSET_TEST
+  /* Solaris 2.5.x and 2.6 tzset sometimes modify the storage returned
+     by localtime.  On such systems, we must either use the tzset and
+     localtime wrappers to work around the bug (which sets
+     HAVE_RUN_TZSET_TEST) or make a copy of the structure.  */
+  struct tm copy = *tp;
+  tp = &copy;
+#endif
+
   zone = NULL;
 #if HAVE_TM_ZONE
   /* The POSIX test suite assumes that setting
@@ -759,7 +761,7 @@ my_strftime (CHAR_T *s, size_t maxsize, const CHAR_T *format,
          {
            /* The relevant information is available only via the
               underlying strftime implementation, so use that.  */
-           char ufmt[4];
+           char ufmt[5];
            char *u = ufmt;
            char ubuf[1024]; /* enough for any single format in practice */
            size_t len;
@@ -771,16 +773,17 @@ my_strftime (CHAR_T *s, size_t maxsize, const CHAR_T *format,
            size_t strftime ();
 # endif
 
+           /* The space helps distinguish strftime failure from empty
+              output.  */
+           *u++ = ' ';
            *u++ = '%';
            if (modifier != 0)
              *u++ = modifier;
            *u++ = format_char;
            *u = '\0';
-           ubuf[0] = '\1';
            len = strftime (ubuf, sizeof ubuf, ufmt, tp);
-           if (len == 0 && ubuf[0] != '\0')
-             return 0;
-           cpy (len, ubuf);
+           if (len != 0)
+             cpy (len - 1, ubuf + 1);
          }
          break;
 #endif
@@ -906,10 +909,10 @@ my_strftime (CHAR_T *s, size_t maxsize, const CHAR_T *format,
            }
          while (u_number_value != 0);
 
+       do_number_sign_and_padding:
          if (digits < width)
            digits = width;
 
-       do_number_sign_and_padding:
          if (negative_number)
            *--bufp = L_('-');