]> Savannah Git Hosting - gnulib.git/commitdiff
savewd: port to native MS-Windows
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 27 Aug 2024 21:39:59 +0000 (14:39 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 27 Aug 2024 21:39:59 +0000 (14:39 -0700)
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.

ChangeLog
lib/savewd.c

index 92c89efae30b4edb43daf8385dd3076725938d8c..83dc20f558da9034886b1e7c35998218848ec971 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-08-27  Paul Eggert  <eggert@cs.ucla.edu>
+
+       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  <bruno@clisp.org>
 
        bcopy: Deprecate module.
index 57692c0b3d9166b585d0b65068eefdb16c522d14..216f416f0ecef26c707f317c730d78f1fc14ff27 100644 (file)
 #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;