Wabi patch already merged in new upstream version
[debian/gzip] / lib / unlink.c
index 3e42e28692c373861649eaea61675fc773bf0235..ea1f525dc361192b0a1a7fbd4aa5f44115c9fdba 100644 (file)
@@ -1,6 +1,6 @@
 /* Work around unlink bugs.
 
-   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2009-2018 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -13,7 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
@@ -24,6 +24,8 @@
 #include <string.h>
 #include <sys/stat.h>
 
+#include "dosname.h"
+
 #undef unlink
 
 /* Remove file NAME.
@@ -80,6 +82,16 @@ rpl_unlink (char const *name)
         }
     }
   if (!result)
-    result = unlink (name);
+    {
+#if UNLINK_PARENT_BUG
+      if (len >= 2 && name[len - 1] == '.' && name[len - 2] == '.'
+          && (len == 2 || ISSLASH (name[len - 3])))
+        {
+          errno = EISDIR; /* could also use EPERM */
+          return -1;
+        }
+#endif
+      result = unlink (name);
+    }
   return result;
 }