[tz] [PROPOSED PATCH 3/3] Port C macro defaults to Solaris and Irix.
Paul Eggert
eggert at cs.ucla.edu
Tue Aug 26 00:16:49 UTC 2014
This is mostly for convenience, so that plain 'make' works out of
the box on Solaris, instead of having to run something awkward like
'make CFLAGS="-xc99=all -DHAVE_INCOMPATIBLE_CTIME_R=1"', and
similarly for Irix 6.5.
* private.h (_POSIX_PTHREAD_SEMANTICS):
* private.h, zdump.c (__EXTENSIONS__):
New macros, to make Solaris headers more like what we want out
of the box.
(LLONG_MAX, LLONG_MIN): Default from __LONG_LONG_MAX__ if it's defined.
This simplifies later code.
(SCNdFAST64, PRIdMAX): Don't assume they're defined when
INT_FAST64_MAX is, as that's not true on Solaris 10 + Sun C 5.12.
(PRIuMAX): Likewise, for Solaris 11 + Sun C 5.12.
* zdump.c (HAVE_LOCALTIME_RZ): Default to 1 only if TM_ZONE.
* Makefile, NEWS: Document this.
---
Makefile | 2 +-
NEWS | 5 +++--
private.h | 73 ++++++++++++++++++++++++++++++++++++++++-----------------------
zdump.c | 31 +++++++++++++++++++--------
4 files changed, 73 insertions(+), 38 deletions(-)
diff --git a/Makefile b/Makefile
index 92fad4d..2354a3f 100644
--- a/Makefile
+++ b/Makefile
@@ -111,7 +111,7 @@ LDLIBS=
# -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
-# This defaults to 1 if localtime_rz is known to be available.
+# This defaults to 1 if a working localtime_rz seems to be available.
# localtime_rz can make zdump significantly faster, but is nonstandard.
# -DHAVE_SETTIMEOFDAY=0 if settimeofday does not exist (SVR0?)
# -DHAVE_SETTIMEOFDAY=1 if settimeofday has just 1 arg (SVR4)
diff --git a/NEWS b/NEWS
index 0f4ff2e..3c8b84b 100644
--- a/NEWS
+++ b/NEWS
@@ -101,8 +101,9 @@ Unreleased, experimental changes
the date it updates the wtmpx file if _PATH_WTMPX is defined.
This affects GNU/Linux and similar systems.
- For easier maintenance later, some C code has been simplified
- and some lint has been removed.
+ For easier maintenance later, some C code has been simplified,
+ some lint has been removed, and the code has been tweaked so that
+ plain 'make' is more likely to work.
The C type 'bool' is now used for boolean values, instead of 'int'.
diff --git a/private.h b/private.h
index 00a2469..e7f5255 100644
--- a/private.h
+++ b/private.h
@@ -73,6 +73,10 @@
/* Enable tm_gmtoff and tm_zone on GNUish systems. */
#define _GNU_SOURCE 1
+/* Fix asctime_r on Solaris 10. */
+#define _POSIX_PTHREAD_SEMANTICS 1
+/* Enable strtoimax on Solaris 10. */
+#define __EXTENSIONS__ 1
/*
** Nested includes
@@ -163,29 +167,39 @@
# include <inttypes.h>
#endif
-#ifndef INT_FAST64_MAX
/* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
-#if defined LLONG_MAX || defined __LONG_LONG_MAX__
-typedef long long int_fast64_t;
+#ifdef __LONG_LONG_MAX__
+# ifndef LLONG_MAX
+# define LLONG_MAX __LONG_LONG_MAX__
+# endif
+# ifndef LLONG_MIN
+# define LLONG_MIN (-1 - LLONG_MAX)
+# endif
+#endif
+
+#ifndef INT_FAST64_MAX
# ifdef LLONG_MAX
+typedef long long int_fast64_t;
# define INT_FAST64_MIN LLONG_MIN
# define INT_FAST64_MAX LLONG_MAX
# else
-# define INT_FAST64_MIN (-1 - __LONG_LONG_MAX__)
-# define INT_FAST64_MAX __LONG_LONG_MAX__
-# endif
-# define SCNdFAST64 "lld"
-#else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
-#if (LONG_MAX >> 31) < 0xffffffff
+# if (LONG_MAX >> 31) < 0xffffffff
Please use a compiler that supports a 64-bit integer type (or wider);
you may need to compile with "-DHAVE_STDINT_H".
-#endif /* (LONG_MAX >> 31) < 0xffffffff */
+# endif
typedef long int_fast64_t;
-# define INT_FAST64_MIN LONG_MIN
-# define INT_FAST64_MAX LONG_MAX
-# define SCNdFAST64 "ld"
-#endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
-#endif /* !defined INT_FAST64_MAX */
+# define INT_FAST64_MIN LONG_MIN
+# define INT_FAST64_MAX LONG_MAX
+# endif
+#endif
+
+#ifndef SCNdFAST64
+# if INT_FAST64_MAX == LLONG_MAX
+# define SCNdFAST64 "lld"
+# else
+# define SCNdFAST64 "ld"
+# endif
+#endif
#ifndef INT_FAST32_MAX
# if INT_MAX >> 31 == 0
@@ -200,32 +214,39 @@ typedef int int_fast32_t;
#endif
#ifndef INTMAX_MAX
-# if defined LLONG_MAX || defined __LONG_LONG_MAX__
+# ifdef LLONG_MAX
typedef long long intmax_t;
# define strtoimax strtoll
-# define PRIdMAX "lld"
-# ifdef LLONG_MAX
-# define INTMAX_MAX LLONG_MAX
-# define INTMAX_MIN LLONG_MIN
-# else
-# define INTMAX_MAX __LONG_LONG_MAX__
-# define INTMAX_MIN (-1 - __LONG_LONG_MAX__)
-# endif
+# define INTMAX_MAX LLONG_MAX
+# define INTMAX_MIN LLONG_MIN
# else
typedef long intmax_t;
# define strtoimax strtol
-# define PRIdMAX "ld"
# define INTMAX_MAX LONG_MAX
# define INTMAX_MIN LONG_MIN
# endif
#endif
+#ifndef PRIdMAX
+# if INTMAX_MAX == LLONG_MAX
+# define PRIdMAX "lld"
+# else
+# define PRIdMAX "ld"
+# endif
+#endif
+
#ifndef UINTMAX_MAX
# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
typedef unsigned long long uintmax_t;
-# define PRIuMAX "llu"
# else
typedef unsigned long uintmax_t;
+# endif
+#endif
+
+#ifndef PRIuMAX
+# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
+# define PRIuMAX "llu"
+# else
# define PRIuMAX "lu"
# endif
#endif
diff --git a/zdump.c b/zdump.c
index 7326c63..6fdd579 100644
--- a/zdump.c
+++ b/zdump.c
@@ -25,6 +25,8 @@
/* Enable tm_gmtoff and tm_zone on GNUish systems. */
#define _GNU_SOURCE 1
+/* Enable strtoimax on Solaris 10. */
+#define __EXTENSIONS__ 1
#include "stdio.h" /* for stdout, stderr, perror */
#include "string.h" /* for strcpy */
@@ -63,24 +65,31 @@ typedef int int_fast32_t;
# endif
#endif
+/* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
+#if !defined LLONG_MAX && defined __LONG_LONG_MAX__
+# define LLONG_MAX __LONG_LONG_MAX__
+#endif
+
#ifndef INTMAX_MAX
-# if defined LLONG_MAX || defined __LONG_LONG_MAX__
+# ifdef LLONG_MAX
typedef long long intmax_t;
# define strtoimax strtoll
-# define PRIdMAX "lld"
-# ifdef LLONG_MAX
-# define INTMAX_MAX LLONG_MAX
-# else
-# define INTMAX_MAX __LONG_LONG_MAX__
-# endif
+# define INTMAX_MAX LLONG_MAX
# else
typedef long intmax_t;
# define strtoimax strtol
-# define PRIdMAX "ld"
# define INTMAX_MAX LONG_MAX
# endif
#endif
+#ifndef PRIdMAX
+# if INTMAX_MAX == LLONG_MAX
+# define PRIdMAX "lld"
+# else
+# define PRIdMAX "ld"
+# endif
+#endif
+
/* Infer TM_ZONE on systems where this information is known, but suppress
guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */
#if (defined __GLIBC__ \
@@ -99,7 +108,11 @@ typedef long intmax_t;
#endif
#ifndef HAVE_LOCALTIME_RZ
-# define HAVE_LOCALTIME_RZ (NETBSD_INSPIRED && USE_LTZ)
+# ifdef TM_ZONE
+# define HAVE_LOCALTIME_RZ (NETBSD_INSPIRED && USE_LTZ)
+# else
+# define HAVE_LOCALTIME_RZ 0
+# endif
#endif
#ifndef HAVE_TZSET
--
1.9.1
More information about the tz
mailing list