On 2024-08-27 13:34, Bruno Haible wrote:
gllib\savewd.c(73,27): warning: implicit declaration of function 'fork' is
invalid in C99 [-Wimplicit-function-declaration]
Perhaps the attached patch?
From 4e624ff79120231a78b85a2302d037e205c69dd3 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Tue, 27 Aug 2024 14:23:59 -0700
Subject: [PATCH] savewd: port to native MS-Windows
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* lib/savewd.c (fork) [_WIN32 && !__CYGWIN]: New static function.
(savewd_save): Don’t fork on MS-Windows, or if O_SEARCH != O_RDONLY.
---
ChangeLog | 6 ++++++
lib/savewd.c | 13 ++++++++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 767f51f9d3..d80aa2107d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-08-27 Paul Eggert <egg...@cs.ucla.edu>
+
+ savewd: port to native MS-Windows
+ * lib/savewd.c (fork) [_WIN32 && !__CYGWIN]: New static function.
+ (savewd_save): Don’t fork on MS-Windows, or if O_SEARCH != O_RDONLY.
+
2024-08-27 Bruno Haible <br...@clisp.org>
write-any-file: Don't reference an undefined function on native Windows.
diff --git a/lib/savewd.c b/lib/savewd.c
index 57692c0b3d..7c5ba17c42 100644
--- a/lib/savewd.c
+++ b/lib/savewd.c
@@ -36,6 +36,10 @@
#include "fcntl-safer.h"
#include "filename.h"
+#if defined _WIN32 && !defined __CYGWIN__
+static pid_t fork (void) { assure (false); }
+#endif
+
/* Save the working directory into *WD, if it hasn't been saved
already. Return true if a child has been forked to do the real
work. */
@@ -54,7 +58,14 @@ savewd_save (struct savewd *wd)
wd->val.fd = fd;
break;
}
- if (errno != EACCES && errno != ESTALE)
+# if O_SEARCH != O_RDONLY || (defined _WIN32 && !defined __CYGWIN__)
+ /* There is no point to forking if O_SEARCH conforms to POSIX,
+ or on native MS-Windows which lacks 'fork'. */
+ bool try_fork = false;
+# else
+ bool try_fork = errno == EACCES || errno == ESTALE;
+# endif
+ if (!try_fork)
{
wd->state = ERROR_STATE;
wd->val.errnum = errno;
--
2.43.0