From: Paul Eggert Date: Tue, 27 Aug 2024 21:39:59 +0000 (-0700) Subject: savewd: port to native MS-Windows X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=e4399abd41791a3d193de2e4e32ec0407507a325;p=gnulib.git savewd: port to native MS-Windows Problem reported by Bruno Haible in: https://lists.gnu.org/r/bug-gnulib/2024-08/msg00187.html * lib/savewd.c (fork) [_WIN32 && !__CYGWIN]: New macro. (savewd_save): Don’t fork on MS-Windows, or if O_SEARCH != O_RDONLY. --- diff --git a/ChangeLog b/ChangeLog index 92c89efae3..83dc20f558 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-08-27 Paul Eggert + + savewd: port to native MS-Windows + Problem reported by Bruno Haible in: + https://lists.gnu.org/r/bug-gnulib/2024-08/msg00187.html + * lib/savewd.c (fork) [_WIN32 && !__CYGWIN]: New macro. + (savewd_save): Don’t fork on MS-Windows, or if O_SEARCH != O_RDONLY. + 2024-08-27 Bruno Haible bcopy: Deprecate module. diff --git a/lib/savewd.c b/lib/savewd.c index 57692c0b3d..216f416f0e 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__ +# define fork() (assure (false), -1) +#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;