From ad8c1e6a094435bd3e1fe1167df68c58d86c749b Mon Sep 17 00:00:00 2001 From: David Malone Date: Mon, 28 Aug 2000 15:45:42 +0000 Subject: 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 --- lib/libc/stdio/remove.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/libc/stdio/remove.c') diff --git a/lib/libc/stdio/remove.c b/lib/libc/stdio/remove.c index cca7cb627163..3518b68c7475 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 +#include #include #include @@ -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)); } -- cgit v1.2.3