From: Bruno Haible <bruno@clisp.org>
Date: Sun, 3 Jul 2022 09:58:03 +0000 (+0200)
Subject: supersede: Support the file name "/dev/null" on native Windows.
X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=bfa22a64998a273f5b3790df84dd214fe943afbd;p=gnulib.git

supersede: Support the file name "/dev/null" on native Windows.

* lib/supersede.c (open_supersede): On native Windows, map "/dev/null"
to "NUL".
---

diff --git a/ChangeLog b/ChangeLog
index a5b6552d0a..a575aba478 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2022-07-03  Bruno Haible  <bruno@clisp.org>
+
+	supersede: Support the file name "/dev/null" on native Windows.
+	* lib/supersede.c (open_supersede): On native Windows, map "/dev/null"
+	to "NUL".
+
 2022-06-23  Jim Meyering  <meyering@fb.com>
 
 	maint.mk: fix syntax-check for unnecessary hash.h header use
diff --git a/lib/supersede.c b/lib/supersede.c
index 45b90829b2..898c565ade 100644
--- a/lib/supersede.c
+++ b/lib/supersede.c
@@ -93,6 +93,11 @@ open_supersede (const char *filename, int flags, mode_t mode,
     0;
     #endif
 
+#if defined _WIN32 && ! defined __CYGWIN__
+  if (strcmp (filename, "/dev/null") == 0)
+    filename = "NUL";
+#endif
+
   if (supersede_if_exists)
     {
       if (supersede_if_does_not_exist)