aboutsummaryrefslogtreecommitdiffstats
path: root/lib/nstrftime.c
diff options
context:
space:
mode:
authorVibhav Pant2020-08-21 14:04:35 +0530
committerVibhav Pant2020-08-21 14:04:35 +0530
commitf0f8d7b82492e741950c363a03b886965c91b1b0 (patch)
tree19b716830b1ebabc0d7d75949c4e6800c0f104ad /lib/nstrftime.c
parent9e64a087c4d167e7ec1c4e22bea3e6af53b563de (diff)
parentc818c29771d3cb51875643b2f6c894073e429dd2 (diff)
downloademacs-feature/native-comp-macos-fixes.tar.gz
emacs-feature/native-comp-macos-fixes.zip
Merge branch 'feature/native-comp' into feature/native-comp-macos-fixesfeature/native-comp-macos-fixes
Diffstat (limited to 'lib/nstrftime.c')
-rw-r--r--lib/nstrftime.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/nstrftime.c b/lib/nstrftime.c
index 2816cf4d58b..7d5a97f7635 100644
--- a/lib/nstrftime.c
+++ b/lib/nstrftime.c
@@ -21,7 +21,6 @@
21# define HAVE_TM_GMTOFF 1 21# define HAVE_TM_GMTOFF 1
22# define HAVE_TM_ZONE 1 22# define HAVE_TM_ZONE 1
23# define HAVE_TZNAME 1 23# define HAVE_TZNAME 1
24# define HAVE_TZSET 1
25# include "../locale/localeinfo.h" 24# include "../locale/localeinfo.h"
26#else 25#else
27# include <config.h> 26# include <config.h>
@@ -34,6 +33,7 @@
34#endif 33#endif
35 34
36#include <ctype.h> 35#include <ctype.h>
36#include <errno.h>
37#include <time.h> 37#include <time.h>
38 38
39#if HAVE_TZNAME && !HAVE_DECL_TZNAME 39#if HAVE_TZNAME && !HAVE_DECL_TZNAME
@@ -163,7 +163,10 @@ extern char *tzname[];
163 size_t _w = pad == L_('-') || width < 0 ? 0 : width; \ 163 size_t _w = pad == L_('-') || width < 0 ? 0 : width; \
164 size_t _incr = _n < _w ? _w : _n; \ 164 size_t _incr = _n < _w ? _w : _n; \
165 if (_incr >= maxsize - i) \ 165 if (_incr >= maxsize - i) \
166 return 0; \ 166 { \
167 errno = ERANGE; \
168 return 0; \
169 } \
167 if (p) \ 170 if (p) \
168 { \ 171 { \
169 if (_n < _w) \ 172 if (_n < _w) \
@@ -365,7 +368,7 @@ tm_diff (const struct tm *a, const struct tm *b)
365#define ISO_WEEK1_WDAY 4 /* Thursday */ 368#define ISO_WEEK1_WDAY 4 /* Thursday */
366#define YDAY_MINIMUM (-366) 369#define YDAY_MINIMUM (-366)
367static int iso_week_days (int, int); 370static int iso_week_days (int, int);
368#ifdef __GNUC__ 371#if defined __GNUC__ || defined __clang__
369__inline__ 372__inline__
370#endif 373#endif
371static int 374static int
@@ -389,7 +392,6 @@ iso_week_days (int yday, int wday)
389#endif 392#endif
390 393
391#ifdef my_strftime 394#ifdef my_strftime
392# undef HAVE_TZSET
393# define extra_args , tz, ns 395# define extra_args , tz, ns
394# define extra_args_spec , timezone_t tz, int ns 396# define extra_args_spec , timezone_t tz, int ns
395#else 397#else
@@ -449,6 +451,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
449 size_t maxsize = (size_t) -1; 451 size_t maxsize = (size_t) -1;
450#endif 452#endif
451 453
454 int saved_errno = errno;
452 int hour12 = tp->tm_hour; 455 int hour12 = tp->tm_hour;
453#ifdef _NL_CURRENT 456#ifdef _NL_CURRENT
454 /* We cannot make the following values variables since we must delay 457 /* We cannot make the following values variables since we must delay
@@ -523,7 +526,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
523 { 526 {
524 /* POSIX.1 requires that local time zone information be used as 527 /* POSIX.1 requires that local time zone information be used as
525 though strftime called tzset. */ 528 though strftime called tzset. */
526# if HAVE_TZSET 529# ifndef my_strftime
527 if (!*tzset_called) 530 if (!*tzset_called)
528 { 531 {
529 tzset (); 532 tzset ();
@@ -1188,7 +1191,13 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
1188 time_t t; 1191 time_t t;
1189 1192
1190 ltm = *tp; 1193 ltm = *tp;
1194 ltm.tm_yday = -1;
1191 t = mktime_z (tz, &ltm); 1195 t = mktime_z (tz, &ltm);
1196 if (ltm.tm_yday < 0)
1197 {
1198 errno = EOVERFLOW;
1199 return 0;
1200 }
1192 1201
1193 /* Generate string value for T using time_t arithmetic; 1202 /* Generate string value for T using time_t arithmetic;
1194 this works even if sizeof (long) < sizeof (time_t). */ 1203 this works even if sizeof (long) < sizeof (time_t). */
@@ -1417,7 +1426,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
1417 1426
1418 /* POSIX.1 requires that local time zone information be used as 1427 /* POSIX.1 requires that local time zone information be used as
1419 though strftime called tzset. */ 1428 though strftime called tzset. */
1420# if HAVE_TZSET 1429# ifndef my_strftime
1421 if (!*tzset_called) 1430 if (!*tzset_called)
1422 { 1431 {
1423 tzset (); 1432 tzset ();
@@ -1486,5 +1495,6 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
1486 *p = L_('\0'); 1495 *p = L_('\0');
1487#endif 1496#endif
1488 1497
1498 errno = saved_errno;
1489 return i; 1499 return i;
1490} 1500}