summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/remove.c
diff options
context:
space:
mode:
authordwmalone <dwmalone@FreeBSD.org>2000-08-28 15:45:42 +0000
committerdwmalone <dwmalone@FreeBSD.org>2000-08-28 15:45:42 +0000
commitb008bd149c5c4e3b67b8d8dde1ae0fc073f68b7a (patch)
tree90ce1d6db92cec01d19457f54f73f319fbb70340 /lib/libc/stdio/remove.c
parent2ff526fc5085532f04f24f561321882088348b6c (diff)
downloadFreeBSD-src-b008bd149c5c4e3b67b8d8dde1ae0fc073f68b7a.zip
FreeBSD-src-b008bd149c5c4e3b67b8d8dde1ae0fc073f68b7a.tar.gz
According to the susv2 man pages I have, remove(3) should act as
rmdir(2) on directories and unlink(2) otherwise. This modification, and most of the man page update has been obtined from OpenBSD. This was spotted by someone on a mailing lists a few months ago, but I've lost their mail. Reviewed by: sheldonh
Diffstat (limited to 'lib/libc/stdio/remove.c')
-rw-r--r--lib/libc/stdio/remove.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/libc/stdio/remove.c b/lib/libc/stdio/remove.c
index cca7cb6..3518b68 100644
--- a/lib/libc/stdio/remove.c
+++ b/lib/libc/stdio/remove.c
@@ -42,6 +42,8 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include <sys/types.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
@@ -49,5 +51,11 @@ int
remove(file)
const char *file;
{
+ struct stat sb;
+
+ if (lstat(file, &sb) < 0)
+ return (-1);
+ if (S_ISDIR(sb.st_mode))
+ return (rmdir(file));
return (unlink(file));
}
OpenPOWER on IntegriCloud