Handle Windows nul device in unlink-if-ordinary.c

Message ID 20230106082314.2091-1-anothername27-unity@yahoo.com
State New
Headers
Series Handle Windows nul device in unlink-if-ordinary.c |

Commit Message

Li, Pan2 via Gcc-patches Jan. 6, 2023, 8:23 a.m. UTC
  From: Himal <himalr@proton.me>

Hi,

This might be a better fix.

Thanks.

---
 libiberty/unlink-if-ordinary.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Patch

diff --git a/libiberty/unlink-if-ordinary.c b/libiberty/unlink-if-ordinary.c
index 84328b216..e765ac8b1 100644
--- a/libiberty/unlink-if-ordinary.c
+++ b/libiberty/unlink-if-ordinary.c
@@ -62,6 +62,12 @@  was made to unlink the file because it is special.
 int
 unlink_if_ordinary (const char *name)
 {
+/* MS-Windows 'stat' function (and in turn, S_ISREG)
+   reports the null device as a regular file.  */
+#ifdef _WIN32
+  if (stricmp (name, "nul") == 0)
+    return 1;
+#endif
   struct stat st;
 
   if (lstat (name, &st) == 0