aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert2019-12-06 15:16:15 -0800
committerPaul Eggert2019-12-06 15:17:08 -0800
commitc4cd2a0b9f251ed830ef32ac6537e62ae5e3d944 (patch)
tree25aec8ec7432bae87fd6b38f06a6d191d96151c4 /lib
parent99ad65eda44e3b6edcc51cf0fb70ea499c3ccb07 (diff)
downloademacs-c4cd2a0b9f251ed830ef32ac6537e62ae5e3d944.tar.gz
emacs-c4cd2a0b9f251ed830ef32ac6537e62ae5e3d944.zip
Update from Gnulib
This incorporates: 2019-12-06 nstrftime: better width support for %N, %z 2019-12-03 Avoid hassles caused by [[noreturn]] in C++ 2019-12-02 Fix mistakes in --enable-threads=isoc fixes from 2019-12-01 * admin/merge-gnulib (AVOIDED_MODULES): Avoid pthread-h. * lib/_Noreturn.h, lib/nstrftime.c, m4/gnulib-common.m4: * m4/timer_time.m4: Copy from Gnulib. * lib/gnulib.mk.in: Regenerate.
Diffstat (limited to 'lib')
-rw-r--r--lib/_Noreturn.h9
-rw-r--r--lib/gnulib.mk.in1
-rw-r--r--lib/nstrftime.c138
3 files changed, 68 insertions, 80 deletions
diff --git a/lib/_Noreturn.h b/lib/_Noreturn.h
index db9b45554c5..7570f828883 100644
--- a/lib/_Noreturn.h
+++ b/lib/_Noreturn.h
@@ -17,7 +17,14 @@
17#ifndef _Noreturn 17#ifndef _Noreturn
18# if (defined __cplusplus \ 18# if (defined __cplusplus \
19 && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \ 19 && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
20 || (defined _MSC_VER && 1900 <= _MSC_VER))) 20 || (defined _MSC_VER && 1900 <= _MSC_VER)) \
21 && 0)
22 /* [[noreturn]] is not practically usable, because with it the syntax
23 extern _Noreturn void func (...);
24 would not be valid; such a declaration would only be valid with 'extern'
25 and '_Noreturn' swapped, or without the 'extern' keyword. However, some
26 AIX system header files and several gnulib header files use precisely
27 this syntax with 'extern'. */
21# define _Noreturn [[noreturn]] 28# define _Noreturn [[noreturn]]
22# elif ((!defined __cplusplus || defined __clang__) \ 29# elif ((!defined __cplusplus || defined __clang__) \
23 && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \ 30 && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in
index 8e3b569b94f..4d5798b06e3 100644
--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -51,6 +51,7 @@
51# --avoid=nl_langinfo \ 51# --avoid=nl_langinfo \
52# --avoid=openat-die \ 52# --avoid=openat-die \
53# --avoid=opendir \ 53# --avoid=opendir \
54# --avoid=pthread-h \
54# --avoid=raise \ 55# --avoid=raise \
55# --avoid=save-cwd \ 56# --avoid=save-cwd \
56# --avoid=select \ 57# --avoid=select \
diff --git a/lib/nstrftime.c b/lib/nstrftime.c
index 461dadb2929..4eae1dc4ebb 100644
--- a/lib/nstrftime.c
+++ b/lib/nstrftime.c
@@ -162,19 +162,20 @@ extern char *tzname[];
162# define advance(P, N) ((P) += (N)) 162# define advance(P, N) ((P) += (N))
163#endif 163#endif
164 164
165#define add(n, f) \ 165#define add(n, f) width_add (width, n, f)
166#define width_add(width, n, f) \
166 do \ 167 do \
167 { \ 168 { \
168 size_t _n = (n); \ 169 size_t _n = (n); \
169 size_t _w = (width < 0 ? 0 : width); \ 170 size_t _w = pad == L_('-') || width < 0 ? 0 : width; \
170 size_t _incr = _n < _w ? _w : _n; \ 171 size_t _incr = _n < _w ? _w : _n; \
171 if (_incr >= maxsize - i) \ 172 if (_incr >= maxsize - i) \
172 return 0; \ 173 return 0; \
173 if (p) \ 174 if (p) \
174 { \ 175 { \
175 if (digits == 0 && _n < _w) \ 176 if (_n < _w) \
176 { \ 177 { \
177 size_t _delta = width - _n; \ 178 size_t _delta = _w - _n; \
178 if (pad == L_('0') || pad == L_('+')) \ 179 if (pad == L_('0') || pad == L_('+')) \
179 memset_zero (p, _delta); \ 180 memset_zero (p, _delta); \
180 else \ 181 else \
@@ -186,15 +187,17 @@ extern char *tzname[];
186 i += _incr; \ 187 i += _incr; \
187 } while (0) 188 } while (0)
188 189
190#define add1(c) width_add1 (width, c)
189#if FPRINTFTIME 191#if FPRINTFTIME
190# define add1(C) add (1, fputc (C, p)) 192# define width_add1(width, c) width_add (width, 1, fputc (c, p))
191#else 193#else
192# define add1(C) add (1, *p = C) 194# define width_add1(width, c) width_add (width, 1, *p = c)
193#endif 195#endif
194 196
197#define cpy(n, s) width_cpy (width, n, s)
195#if FPRINTFTIME 198#if FPRINTFTIME
196# define cpy(n, s) \ 199# define width_cpy(width, n, s) \
197 add ((n), \ 200 width_add (width, n, \
198 do \ 201 do \
199 { \ 202 { \
200 if (to_lowcase) \ 203 if (to_lowcase) \
@@ -214,8 +217,8 @@ extern char *tzname[];
214 while (0) \ 217 while (0) \
215 ) 218 )
216#else 219#else
217# define cpy(n, s) \ 220# define width_cpy(width, n, s) \
218 add ((n), \ 221 width_add (width, n, \
219 if (to_lowcase) \ 222 if (to_lowcase) \
220 memcpy_lowcase (p, (s), _n LOCALE_ARG); \ 223 memcpy_lowcase (p, (s), _n LOCALE_ARG); \
221 else if (to_uppcase) \ 224 else if (to_uppcase) \
@@ -435,9 +438,10 @@ my_strftime (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
435libc_hidden_def (my_strftime) 438libc_hidden_def (my_strftime)
436#endif 439#endif
437 440
438/* Just like my_strftime, above, but with two more parameters. 441/* Just like my_strftime, above, but with more parameters.
439 UPCASE indicate that the result should be converted to upper case, 442 UPCASE indicates that the result should be converted to upper case.
440 and *TZSET_CALLED indicates whether tzset has been called here. */ 443 YR_SPEC and WIDTH specify the padding and width for the year.
444 *TZSET_CALLED indicates whether tzset has been called here. */
441static size_t 445static size_t
442__strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) 446__strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
443 const CHAR_T *format, 447 const CHAR_T *format,
@@ -556,7 +560,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
556 560
557 for (f = format; *f != '\0'; width = -1, f++) 561 for (f = format; *f != '\0'; width = -1, f++)
558 { 562 {
559 int pad = 0; /* Padding for number ('-', '_', or 0). */ 563 int pad = 0; /* Padding for number ('_', '-', '+', '0', or 0). */
560 int modifier; /* Field modifier ('E', 'O', or 0). */ 564 int modifier; /* Field modifier ('E', 'O', or 0). */
561 int digits = 0; /* Max digits for numeric format. */ 565 int digits = 0; /* Max digits for numeric format. */
562 int number_value; /* Numeric value to be printed. */ 566 int number_value; /* Numeric value to be printed. */
@@ -565,7 +569,6 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
565 bool always_output_a_sign; /* +/- should always be output. */ 569 bool always_output_a_sign; /* +/- should always be output. */
566 int tz_colon_mask; /* Bitmask of where ':' should appear. */ 570 int tz_colon_mask; /* Bitmask of where ':' should appear. */
567 const CHAR_T *subfmt; 571 const CHAR_T *subfmt;
568 CHAR_T sign_char;
569 CHAR_T *bufp; 572 CHAR_T *bufp;
570 CHAR_T buf[1 573 CHAR_T buf[1
571 + 2 /* for the two colons in a %::z or %:::z time zone */ 574 + 2 /* for the two colons in a %::z or %:::z time zone */
@@ -1035,59 +1038,34 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
1035 while (u_number_value != 0 || tz_colon_mask != 0); 1038 while (u_number_value != 0 || tz_colon_mask != 0);
1036 1039
1037 do_number_sign_and_padding: 1040 do_number_sign_and_padding:
1038 if (digits < width) 1041 if (pad == 0)
1039 digits = width; 1042 pad = L_('0');
1040 1043 if (width < 0)
1041 sign_char = (negative_number ? L_('-') 1044 width = digits;
1042 : always_output_a_sign ? L_('+')
1043 : 0);
1044
1045 if (pad == L_('-'))
1046 {
1047 if (sign_char)
1048 add1 (sign_char);
1049 }
1050 else
1051 {
1052 int padding = digits - (buf + (sizeof (buf) / sizeof (buf[0]))
1053 - bufp) - !!sign_char;
1054
1055 if (padding > 0)
1056 {
1057 if (pad == L_('_'))
1058 {
1059 if ((size_t) padding >= maxsize - i)
1060 return 0;
1061
1062 if (p)
1063 memset_space (p, padding);
1064 i += padding;
1065 width = width > padding ? width - padding : 0;
1066 if (sign_char)
1067 add1 (sign_char);
1068 }
1069 else
1070 {
1071 if ((size_t) digits >= maxsize - i)
1072 return 0;
1073
1074 if (sign_char)
1075 add1 (sign_char);
1076 1045
1077 if (p) 1046 {
1078 memset_zero (p, padding); 1047 CHAR_T sign_char = (negative_number ? L_('-')
1079 i += padding; 1048 : always_output_a_sign ? L_('+')
1080 width = 0; 1049 : 0);
1081 } 1050 int numlen = buf + sizeof buf / sizeof buf[0] - bufp;
1082 } 1051 int shortage = width - !!sign_char - numlen;
1083 else 1052 int padding = pad == L_('-') || shortage <= 0 ? 0 : shortage;
1084 { 1053
1085 if (sign_char) 1054 if (sign_char)
1086 add1 (sign_char); 1055 {
1087 } 1056 if (pad == L_('_'))
1088 } 1057 {
1058 if (p)
1059 memset_space (p, padding);
1060 i += padding;
1061 width -= padding;
1062 }
1063 width_add1 (0, sign_char);
1064 width--;
1065 }
1089 1066
1090 cpy (buf + sizeof (buf) / sizeof (buf[0]) - bufp, bufp); 1067 cpy (numlen, bufp);
1068 }
1091 break; 1069 break;
1092 1070
1093 case L_('F'): 1071 case L_('F'):
@@ -1153,19 +1131,21 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
1153 case L_('N'): /* GNU extension. */ 1131 case L_('N'): /* GNU extension. */
1154 if (modifier == L_('E')) 1132 if (modifier == L_('E'))
1155 goto bad_format; 1133 goto bad_format;
1156 1134 {
1157 number_value = ns; 1135 int n = ns, ns_digits = 9;
1158 if (width == -1) 1136 if (width <= 0)
1159 width = 9; 1137 width = ns_digits;
1160 else 1138 int ndigs = ns_digits;
1161 { 1139 while (width < ndigs || (1 < ndigs && n % 10 == 0))
1162 /* Take an explicit width less than 9 as a precision. */ 1140 ndigs--, n /= 10;
1163 int j; 1141 for (int i = ndigs; 0 < i; i--)
1164 for (j = width; j < 9; j++) 1142 buf[i - 1] = n % 10 + L_('0'), n /= 10;
1165 number_value /= 10; 1143 if (!pad)
1166 } 1144 pad = L_('0');
1167 1145 width_cpy (0, ndigs, buf);
1168 DO_NUMBER (width, number_value); 1146 width_add (width - ndigs, 0, (void) 0);
1147 }
1148 break;
1169#endif 1149#endif
1170 1150
1171 case L_('n'): 1151 case L_('n'):