Merge remote-tracking branch 'local-2.0/stable-2.0'
[bpt/guile.git] / lib / strftime.c
index c6a9ed2..7743f52 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2001, 2003-2007, 2009-2010 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2001, 2003-2007, 2009-2012 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.
@@ -48,8 +48,11 @@ extern char *tzname[];
    GB18030, EUC-TW, BIG5, BIG5-HKSCS, CP950, EUC-JP, EUC-KR, CP949,
    SHIFT_JIS, CP932, JOHAB) are safe for formats, because the byte '%'
    cannot occur in a multibyte character except in the first byte.
-   But this does not hold for the DEC-HANYU encoding used on OSF/1.  */
-#if !defined __osf__
+
+   The DEC-HANYU encoding used on OSF/1 is not safe for formats, but
+   this encoding has never been seen in real-life use, so we ignore
+   it.  */
+#if !(defined __osf__ && 0)
 # define MULTIBYTE_IS_FORMAT_SAFE 1
 #endif
 #define DO_MULTIBYTE (! MULTIBYTE_IS_FORMAT_SAFE)
@@ -169,15 +172,16 @@ extern char *tzname[];
 #define add(n, f)                                                             \
   do                                                                          \
     {                                                                         \
-      int _n = (n);                                                           \
-      int _delta = width - _n;                                                \
-      int _incr = _n + (_delta > 0 ? _delta : 0);                             \
-      if ((size_t) _incr >= maxsize - i)                                      \
+      size_t _n = (n);                                                        \
+      size_t _w = (width < 0 ? 0 : width);                                    \
+      size_t _incr = _n < _w ? _w : _n;                                       \
+      if (_incr >= maxsize - i)                                               \
         return 0;                                                             \
       if (p)                                                                  \
         {                                                                     \
-          if (digits == 0 && _delta > 0)                                      \
+          if (digits == 0 && _n < _w)                                         \
             {                                                                 \
+              size_t _delta = width - _n;                                     \
               if (pad == L_('0'))                                             \
                 memset_zero (p, _delta);                                      \
               else                                                            \
@@ -285,7 +289,7 @@ extern char *tzname[];
 #  define TOLOWER(Ch, L) tolower (Ch)
 # endif
 #endif
-/* We don't use `isdigit' here since the locale dependent
+/* 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.  */
@@ -433,7 +437,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
 #ifdef _NL_CURRENT
   /* We cannot make the following values variables since we must delay
      the evaluation of these values until really needed since some
-     expressions might not be valid in every situation.  The `struct tm'
+     expressions might not be valid in every situation.  The 'struct tm'
      might be generated by a strptime() call that initialized
      only a few elements.  Dereference the pointers only if the format
      requires this.  Then it is ok to fail if the pointers are invalid.  */
@@ -892,7 +896,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
           goto do_number_body;
 
         do_number_spacepad:
-          /* Force `_' flag unless overridden by `0' or `-' flag.  */
+          /* Force '_' flag unless overridden by '0' or '-' flag.  */
           if (pad != L_('0') && pad != L_('-'))
             pad = L_('_');