make remove(3) remove directories as well

This commit is contained in:
David van Moolenbroek 2009-07-12 14:44:37 +00:00
parent f80aaae86a
commit 1d0e43c8f1

View file

@ -4,10 +4,24 @@
/* $Header$ */ /* $Header$ */
#include <stdio.h> #include <stdio.h>
#include <errno.h>
int _rmdir(const char *path);
int _unlink(const char *path); int _unlink(const char *path);
int int
remove(const char *filename) { 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;
} }