On 2025-10-23 05:12, Manuela Friedrich wrote:
If you could just commit the cange I can test head revision again.

I committed a fancier version of the change (attached) along with some other changes, some of which are related to this issue. Please give the latest head a try. Thanks.
From cd994a904cbf5d1e9864a7ceb43641b2f2b0fb72 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Thu, 23 Oct 2025 15:03:07 -0700
Subject: [PROPOSED 1/2] Simplify !HAVE_POSIX_DECLS situation

Restrict !HAVE_POSIX_DECLS to the time.h-related declarations,
moving the getopt-related ones to !HAVE_UNISTD_H.
This better matches what happens on MS-Windows nowadays.
* Makefile, NEWS: Mention this.
* date.c, zdump.c, zic.c (getopt, optarg, optind) [!HAVE_POSIX_DECLS]:
Remove, as private.h now arranges this.
* private.h (getopt, optarg, optind) [!HAVE_UNISTD_H]: New decls.
* zic.c (link, mkdir) [!HAVE_POSIX_DECLS]: Remove; not needed now.
---
 Makefile  |  2 +-
 NEWS      |  3 +++
 date.c    |  5 -----
 private.h |  5 +++++
 zdump.c   |  7 -------
 zic.c     | 11 -----------
 6 files changed, 9 insertions(+), 24 deletions(-)

diff --git a/Makefile b/Makefile
index b172542a..8f85fcfd 100644
--- a/Makefile
+++ b/Makefile
@@ -265,7 +265,7 @@ LDLIBS=
 #  -DHAVE_MALLOC_ERRNO=0 if malloc etc. do not set errno on failure.
 #  -DHAVE_MEMPCPY=1 if your system has mempcpy, 0 if not (default is guessed)
 #  -DHAVE_POSIX_DECLS=0 if your system's include files do not declare
-#	functions like 'link' or variables like 'tzname' required by POSIX
+#	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_STDCKDINT_H=0 if neither <stdckdint.h> nor substitutes like
diff --git a/NEWS b/NEWS
index 8253cfb6..c605a1fb 100644
--- a/NEWS
+++ b/NEWS
@@ -95,6 +95,9 @@ Unreleased, experimental changes
     tzcode now uses strnlen to improve asymptotic performance a bit.
     Compile with -DHAVE_STRNLEN=0 if your platform lacks it.
 
+    tzcode now hand-declares unistd.h-provided symbols like getopt
+    if HAVE_UNISTD_H=0, not if HAVE_POSIX_DECLS=0.
+
     tzset etc. now have an experimental OPENAT_TZDIR option;
     see Makefile and localtime.c for details.
 
diff --git a/date.c b/date.c
index ba62c0b5..4e483678 100644
--- a/date.c
+++ b/date.c
@@ -31,11 +31,6 @@
 #include <locale.h>
 #include <stdio.h>
 
-#if !HAVE_POSIX_DECLS
-extern char *		optarg;
-extern int		optind;
-#endif
-
 static int		retval = EXIT_SUCCESS;
 
 static void		display(const char *, time_t);
diff --git a/private.h b/private.h
index 2563ed7c..8d3d6404 100644
--- a/private.h
+++ b/private.h
@@ -262,6 +262,11 @@ strnlen (char const *s, size_t maxlen)
 
 #if HAVE_UNISTD_H
 # include <unistd.h>
+#else
+/* Assume getopt.o or equivalent is linked via Makefile configuration.  */
+int getopt(int, char *const[], char const *);
+extern char *optarg;
+extern int optind;
 #endif /* HAVE_UNISTD_H */
 
 /* SUPPORT_POSIX2008 means the tzcode library should support
diff --git a/zdump.c b/zdump.c
index 93fe05cb..4860e3bc 100644
--- a/zdump.c
+++ b/zdump.c
@@ -61,13 +61,6 @@ enum { SECSPER400YEARS_FITS = SECSPERLYEAR <= INTMAX_MAX / 400 };
 # define timezone_t char **
 #endif
 
-#if !HAVE_POSIX_DECLS
-extern int	getopt(int argc, char * const argv[],
-			const char * options);
-extern char *	optarg;
-extern int	optind;
-#endif
-
 /* The minimum and maximum finite time values.  */
 enum { atime_shift = CHAR_BIT * sizeof(time_t) - 2 };
 static time_t const absolute_min_time =
diff --git a/zic.c b/zic.c
index 34e7d91c..f332c2d9 100644
--- a/zic.c
+++ b/zic.c
@@ -178,17 +178,6 @@ struct zone {
 	zic_t		z_untiltime;
 };
 
-#if !HAVE_POSIX_DECLS
-extern int	getopt(int argc, char * const argv[],
-			const char * options);
-extern int	link(const char * target, const char * linkname);
-# ifndef mkdir
-extern int	mkdir(char const *, mode_t);
-# endif
-extern char *	optarg;
-extern int	optind;
-#endif
-
 #if ! HAVE_SYMLINK
 static ssize_t
 readlink(char const *restrict file, char *restrict buf, size_t size)
-- 
2.48.1

From cc377b074bb15eccaeccf7dadc3392ee7b8326c5 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Thu, 23 Oct 2025 15:05:06 -0700
Subject: [PROPOSED 2/2] Simplify mkdir situation

This better matches what happens on MS-Windows nowadays.
* zic.c (mode_t) [HAVE_DIRECT_H]: Remove; not used.
(mkdir): Always define as a macro if HAVE_DIRECT_H,
and do not declare if !HAVE_POSIX_DECLS.
---
 zic.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/zic.c b/zic.c
index f332c2d9..9a2c0624 100644
--- a/zic.c
+++ b/zic.c
@@ -48,12 +48,7 @@ enum { FORMAT_LEN_GROWTH_BOUND = 5 };
 #ifdef HAVE_DIRECT_H
 # include <direct.h>
 # include <io.h>
-# ifndef mode_t
-#  define mode_t int
-# endif
-# ifndef mkdir
-#  define mkdir(name, mode) _mkdir(name)
-# endif
+# define mkdir(name, mode) _mkdir(name)
 #endif
 
 #ifndef HAVE_GETRANDOM
-- 
2.48.1

Reply via email to