[tz] [PROPOSED 1/2] Default time_t to 64 bits on glibc 2.34+ 32-bit

Paul Eggert eggert at cs.ucla.edu
Wed Oct 26 18:42:04 UTC 2022


* NEWS: Mention this.
* private.h (_TIME_BITS): Default to 64.
---
 NEWS      |  8 ++++++++
 private.h | 12 ++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index bddbd3da..a918aed2 100644
--- a/NEWS
+++ b/NEWS
@@ -57,6 +57,14 @@ Unreleased, experimental changes
     number 2438 comes from the 32-bit limit in the year 2038, plus the
     400-year Gregorian cycle.  (Problem reported by Bradley White.)
 
+    On glibc 2.34 and later, which optionally supports 64-bit time_t
+    on platforms like x86 where time_t was traditionally 32 bits,
+    default time_t to 64 instead of 32 bits.  This lets functions like
+    localtime support timestamps after the year 2038, and fixes
+    year-2038 problems in zic when accessing files dated after 2038.
+    To continue to limit time_t to 32 bits on these platforms, use
+    "make CFLAGS='-D_TIME_BITS=32'".
+
     In C code, prefer C23 keywords to pre-C23 macros for alignof,
     bool, false, and true.  Also, use the following C23 features if
     available: __has_include, unreachable.
diff --git a/private.h b/private.h
index c185d5f3..2c7535d8 100644
--- a/private.h
+++ b/private.h
@@ -127,8 +127,9 @@
 /* Enable strtoimax on pre-C99 Solaris 11.  */
 #define __EXTENSIONS__ 1
 
-/* To avoid having 'stat' fail unnecessarily with errno == EOVERFLOW,
-   enable large files on GNUish systems ...  */
+/* Although tzcode does not call 'stat'-like functions directly, stdio
+   functions may call them.  To avoid having them fail unnecessarily
+   with errno == EOVERFLOW, enable large files on GNUish systems ...  */
 #ifndef _FILE_OFFSET_BITS
 # define _FILE_OFFSET_BITS 64
 #endif
@@ -137,6 +138,13 @@
 /* ... and enable large inode numbers on Mac OS X 10.5 and later.  */
 #define _DARWIN_USE_64_BIT_INODE 1
 
+/* On GNUish systems where time_t might be 32 or 64 bits, use 64.
+   This supports a wider time range, and avoids having 'stat'-like
+   functions fail unnecessarily with errno == EOVERFLOW.  */
+#ifndef _TIME_BITS
+# define _TIME_BITS 64
+#endif
+
 /*
 ** Nested includes
 */
-- 
2.37.2



More information about the tz mailing list