aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src/b2m.c
diff options
context:
space:
mode:
authorPaul Eggert2006-04-04 04:13:02 +0000
committerPaul Eggert2006-04-04 04:13:02 +0000
commitd65b42351fbebde2539d447ecf5443e1725bdce3 (patch)
treedeb0a158f63a41290877cd94550db6d95bd4d500 /lib-src/b2m.c
parentd4d0c924b1b4b6d0a20b21b791b0226ba579f5fb (diff)
downloademacs-d65b42351fbebde2539d447ecf5443e1725bdce3.tar.gz
emacs-d65b42351fbebde2539d447ecf5443e1725bdce3.zip
* lib-src/b2m.c (main): Don't include <limits.h>.
(TM_YEAR_BASE): New macro. (TM_YEAR_IN_ASCTIME_RANGE): Don't define if already defined, so that s/ files can override this. Use the more-conservative range 1000-9999. (main): Check for asctime returning NULL. * lib-src/fakemail.c: Likewise. * src/editfns.c (TM_YEAR_IN_ASCTIME_RANGE): New macro, identical to ../lib-src/b2m.c and ../lib-src/editfns.c. (Fcurrent_time_string): Use it. Document that the year might not consume 4 columns if it's outside the range 1000-9999. Check for asctime failure. Don't assume that the output string length is always exactly 24.
Diffstat (limited to 'lib-src/b2m.c')
-rw-r--r--lib-src/b2m.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/lib-src/b2m.c b/lib-src/b2m.c
index adaa736bcd9..a3ab9a5bb9a 100644
--- a/lib-src/b2m.c
+++ b/lib-src/b2m.c
@@ -26,7 +26,6 @@
26#undef static 26#undef static
27#endif 27#endif
28 28
29#include <limits.h>
30#include <stdio.h> 29#include <stdio.h>
31#include <time.h> 30#include <time.h>
32#include <sys/types.h> 31#include <sys/types.h>
@@ -45,15 +44,13 @@
45 44
46typedef int logical; 45typedef int logical;
47 46
48/* True if TM_YEAR is a struct tm's tm_year value that is acceptable 47#define TM_YEAR_BASE 1900
49 to asctime. Glibc asctime returns a useful string unless TM_YEAR 48
50 is nearly INT_MAX, but the C Standard lets C libraries overrun a 49/* Nonzero if TM_YEAR is a struct tm's tm_year value that causes
51 buffer if TM_YEAR needs more than 4 bytes. */ 50 asctime to have well-defined behavior. */
52#ifdef __GLIBC__ 51#ifndef TM_YEAR_IN_ASCTIME_RANGE
53# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) ((tm_year) <= INT_MAX - 1900)
54#else
55# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) \ 52# define TM_YEAR_IN_ASCTIME_RANGE(tm_year) \
56 (-999 - 1900 <= (tm_year) && (tm_year) <= 9999 - 1900) 53 (1000 - TM_YEAR_BASE <= (tm_year) && (tm_year) <= 9999 - TM_YEAR_BASE)
57#endif 54#endif
58 55
59/* 56/*
@@ -148,9 +145,9 @@ main (argc, argv)
148 Don't use 'ctime', as that might dump core if the hardware clock 145 Don't use 'ctime', as that might dump core if the hardware clock
149 is set to a bizarre value. */ 146 is set to a bizarre value. */
150 tm = localtime (&ltoday); 147 tm = localtime (&ltoday);
151 if (! (tm && TM_YEAR_IN_ASCTIME_RANGE (tm->tm_year))) 148 if (! (tm && TM_YEAR_IN_ASCTIME_RANGE (tm->tm_year)
149 && (today = asctime (tm))))
152 fatal ("current time is out of range"); 150 fatal ("current time is out of range");
153 today = asctime (tm);
154 data.size = 200; 151 data.size = 200;
155 data.buffer = xnew (200, char); 152 data.buffer = xnew (200, char);
156 153