[tz] [PROPOSED] Default to assuming C99 or later

Paul Eggert eggert at cs.ucla.edu
Fri Dec 2 08:35:41 UTC 2022


By default, assume the compiler and library support C99 or later.
Continue to port to C89 platforms only if the new macro
PORT_TO_C89 is nonzero.  This new macro is a transitional aid, and
is planned to be removed in a future version that always assumes
C99 or later.
* Makefile, NEWS: Mention this.
* private.h (PORT_TO_C89): New macro.
(SUPPORT_C89): Move up.
(true, false, bool) [!PORT_TO_C89]: Assume C99 or later.
If !PORT_TO_C89 simply include <inttypes.h> rather than
fooling around with conditional stdint.h, conditional inttypes.h,
and lots of other conditional definitions.
(restrict) [!PORT_TO_C89]: Do not define.
* zdump.c (HAVE_SNPRINTF) [!PORT_TO_C89]: Now true.
---
 Makefile  | 14 ++++++++------
 NEWS      | 11 ++++++-----
 private.h | 35 +++++++++++++++++++++++++----------
 zdump.c   |  2 +-
 4 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/Makefile b/Makefile
index 63f3b5ca..8bee50d8 100644
--- a/Makefile
+++ b/Makefile
@@ -220,7 +220,7 @@ LDLIBS=
 #  -DHAVE_INCOMPATIBLE_CTIME_R if your system's time.h declares
 #	ctime_r and asctime_r incompatibly with the POSIX standard
 #	(Solaris when _POSIX_PTHREAD_SEMANTICS is not defined).
-#  -DHAVE_INTTYPES_H=0 if <inttypes.h> does not work*
+#  -DHAVE_INTTYPES_H=0 if <inttypes.h> does not work*+
 #  -DHAVE_LINK=0 if your system lacks a link function
 #  -DHAVE_LOCALTIME_R=0 if your system lacks a localtime_r function
 #  -DHAVE_LOCALTIME_RZ=0 if you do not want zdump to use localtime_rz
@@ -229,24 +229,24 @@ LDLIBS=
 #  -DHAVE_POSIX_DECLS=0 if your system's include files do not declare
 #	functions like 'link' or variables like 'tzname' required by POSIX
 #  -DHAVE_SETENV=0 if your system lacks the setenv function
-#  -DHAVE_SNPRINTF=0 if your system lacks the snprintf function
+#  -DHAVE_SNPRINTF=0 if your system lacks the snprintf function+
 #  -DHAVE_STDCKDINT_H=0 if neither <stdckdint.h> nor substitutes like
 #	__builtin_add_overflow work*
-#  -DHAVE_STDINT_H=0 if <stdint.h> does not work*
+#  -DHAVE_STDINT_H=0 if <stdint.h> does not work*+
 #  -DHAVE_STRFTIME_L if <time.h> declares locale_t and strftime_l
 #  -DHAVE_STRDUP=0 if your system lacks the strdup function
-#  -DHAVE_STRTOLL=0 if your system lacks the strtoll function
+#  -DHAVE_STRTOLL=0 if your system lacks the strtoll function+
 #  -DHAVE_SYMLINK=0 if your system lacks the symlink function
 #  -DHAVE_SYS_STAT_H=0 if <sys/stat.h> does not work*
 #  -DHAVE_TZSET=0 if your system lacks a tzset function
 #  -DHAVE_UNISTD_H=0 if <unistd.h> does not work*
 #  -DHAVE_UTMPX_H=0 if <utmpx.h> does not work*
 #  -Dlocale_t=XXX if your system uses XXX instead of locale_t
+#  -DPORT_TO_C89 if tzcode should also run on C89 platforms+
 #  -DRESERVE_STD_EXT_IDS if your platform reserves standard identifiers
 #	with external linkage, e.g., applications cannot define 'localtime'.
 #  -Dssize_t=long on hosts like MS-Windows that lack ssize_t
-#  -DSUPPORT_C89 if you build or run tzcode on a C89 platform; this option
-#	is obsolescent and is planned to be removed when C99+ is required.
+#  -DSUPPORT_C89 if the tzcode library should support C89 callers+
 #  -DSUPPRESS_TZDIR to not prepend TZDIR to file names; this has
 #	security implications and is not recommended for general use
 #  -DTHREAD_SAFE to make localtime.c thread-safe, as POSIX requires;
@@ -275,6 +275,8 @@ LDLIBS=
 #  $(GCC_DEBUG_FLAGS) if you are using recent GCC and want lots of checking
 #
 # * Options marked "*" can be omitted if your compiler is C23 compatible.
+# * Options marked "+" are obsolescent and are planned to be removed
+#   once the code assumes C99 or later.
 #
 # Select instrumentation via "make GCC_INSTRUMENT='whatever'".
 GCC_INSTRUMENT = \
diff --git a/NEWS b/NEWS
index 25dcc875..91ec5056 100644
--- a/NEWS
+++ b/NEWS
@@ -3,15 +3,16 @@ News for the tz database
 Unreleased, experimental changes
 
   Briefly:
-    tzcode no longer supports C89 unless built with -DSUPPORT_C89
+    The code now defaults to C99 or later.
     Fix use of C23 attributes.
 
   Changes to code
 
-    tzcode no longer supports C89 by default.  To build or run in a
-    C89 environment, compile with -DSUPPORT_C89, a transitional aid
-    that is planned to be removed in a near-future version, when C99
-    or later will be required.
+    The code by default is now designed for C99 or later.  To build in
+    a C89 environment, compile with -DPORT_TO_C89.  To support C89
+    callers of the tzcode library, compile with -DSUPPORT_C89.  The
+    two new macros are transitional aids planned to be removed in a
+    future version, when C99 or later will be required.
 
     On C23-compatible platforms tzcode no longer uses syntax like
     'static [[noreturn]] void usage(void);'.  Instead, it uses
diff --git a/private.h b/private.h
index 999c1648..1d6ddf73 100644
--- a/private.h
+++ b/private.h
@@ -17,12 +17,25 @@
 ** Thank you!
 */
 
+/* PORT_TO_C89 means the code should work even if the underlying
+   compiler and library support only C89.  SUPPORT_C89 means the
+   tzcode library should support C89 callers in addition to the usual
+   support for C99-and-later callers.  These macros are obsolescent,
+   and the plan is to remove them along with any code needed only when
+   they are nonzero.  */
+#ifndef PORT_TO_C89
+# define PORT_TO_C89 0
+#endif
+#ifndef SUPPORT_C89
+# define SUPPORT_C89 0
+#endif
+
 #ifndef __STDC_VERSION__
 # define __STDC_VERSION__ 0
 #endif
 
 /* Define true, false and bool if they don't work out of the box.  */
-#if __STDC_VERSION__ < 199901
+#if PORT_TO_C89 && __STDC_VERSION__ < 199901
 # define true 1
 # define false 0
 # define bool int
@@ -100,10 +113,6 @@
 # define HAVE_STRDUP 1
 #endif
 
-#ifndef HAVE_STRTOLL
-# define HAVE_STRTOLL 1
-#endif
-
 #ifndef HAVE_SYMLINK
 # define HAVE_SYMLINK 1
 #endif /* !defined HAVE_SYMLINK */
@@ -185,6 +194,9 @@
 
 #include <stddef.h>
 #include <string.h>
+#if !PORT_TO_C89
+# include <inttypes.h>
+#endif
 #include <limits.h>	/* for CHAR_BIT et al. */
 #include <stdlib.h>
 
@@ -254,6 +266,8 @@
 # define R_OK 4
 #endif /* !defined R_OK */
 
+#if PORT_TO_C89
+
 /*
 ** Define HAVE_STDINT_H's default value here, rather than at the
 ** start, since __GLIBC__ and INTMAX_MAX's values depend on
@@ -334,6 +348,9 @@ typedef int int_fast32_t;
 #ifndef INTMAX_MAX
 # ifdef LLONG_MAX
 typedef long long intmax_t;
+#  ifndef HAVE_STRTOLL
+#   define HAVE_STRTOLL true
+#  endif
 #  if HAVE_STRTOLL
 #   define strtoimax strtoll
 #  endif
@@ -396,6 +413,8 @@ typedef unsigned long uintmax_t;
 # define SIZE_MAX ((size_t) -1)
 #endif
 
+#endif /* PORT_TO_C89 */
+
 /* Support ckd_add, ckd_sub, ckd_mul on C23 or recent-enough GCC-like
    hosts, unless compiled with -DHAVE_STDCKDINT_H=0 or with pre-C23 EDG.  */
 #if !defined HAVE_STDCKDINT_H && defined __has_include
@@ -520,7 +539,7 @@ typedef unsigned long uintmax_t;
 # endif
 #endif
 
-#if __STDC_VERSION__ < 199901 && !defined restrict
+#if PORT_TO_C89 && __STDC_VERSION__ < 199901 && !defined restrict
 # define restrict /* empty */
 #endif
 
@@ -704,10 +723,6 @@ extern int daylight;
 extern long altzone;
 #endif
 
-#ifndef SUPPORT_C89
-# define SUPPORT_C89 0
-#endif
-
 /*
 ** The STD_INSPIRED functions are similar, but most also need
 ** declarations if time_tz is defined.
diff --git a/zdump.c b/zdump.c
index bac4a67a..5173c9ac 100644
--- a/zdump.c
+++ b/zdump.c
@@ -15,7 +15,7 @@
 #include <stdio.h>
 
 #ifndef HAVE_SNPRINTF
-# define HAVE_SNPRINTF (199901 <= __STDC_VERSION__)
+# define HAVE_SNPRINTF (!PORT_TO_C89 || 199901 <= __STDC_VERSION__)
 #endif
 
 #ifndef HAVE_LOCALTIME_R
-- 
2.37.2



More information about the tz mailing list