]> Zhao Yanbai Git Server - minix.git/commitdiff
make remove(3) remove directories as well
authorDavid van Moolenbroek <david@minix3.org>
Sun, 12 Jul 2009 14:44:37 +0000 (14:44 +0000)
committerDavid van Moolenbroek <david@minix3.org>
Sun, 12 Jul 2009 14:44:37 +0000 (14:44 +0000)
lib/stdio/remove.c

index 72c5780eaa52ce2c1d0b440293e7887f05c20cfa..7c985ba5920b0aa9e7664f4b94359e6d47bf98b8 100755 (executable)
@@ -4,10 +4,24 @@
 /* $Header$ */
 
 #include       <stdio.h>
+#include       <errno.h>
 
+int _rmdir(const char *path);
 int _unlink(const char *path);
 
 int
 remove(const char *filename) {
-       return _unlink(filename);
+       int saved_errno, retval;
+
+       saved_errno = errno;
+
+       retval = _rmdir(filename);
+
+       if (retval == -1 && errno == ENOTDIR) {
+               errno = saved_errno;
+
+               retval = _unlink(filename);
+       }
+
+       return retval;
 }