summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1997-10-08 05:26:39 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1997-10-08 05:26:39 +0000
commit27915cbcbfdf4bf85f2871974af648740f158e12 (patch)
treec32e8cb31f3c2cb30a92918831d6699ca16f4ca2 /lib/libc
parentd73de057d83f4162095eba11cb8d36dffeb5fd26 (diff)
Use lstat() not stat() so we catch dangling symlinks, hubertf@netbsd.org
Also, update the man page to correspond to reality.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdio/remove.340
-rw-r--r--lib/libc/stdio/remove.c11
2 files changed, 34 insertions, 17 deletions
diff --git a/lib/libc/stdio/remove.3 b/lib/libc/stdio/remove.3
index 17fbd5e8a7b..c210e2b7108 100644
--- a/lib/libc/stdio/remove.3
+++ b/lib/libc/stdio/remove.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: remove.3,v 1.4 1997/06/13 13:46:52 deraadt Exp $
+.\" $OpenBSD: remove.3,v 1.5 1997/10/08 05:26:37 millert Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -35,12 +35,14 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd June 4, 1993
+.\" @(#)remove.3 8.1 (Berkeley) 6/4/93
+.\"
+.Dd October 7, 1997
.Dt REMOVE 3
.Os
.Sh NAME
.Nm remove
-.Nd remove directory entry
+.Nd remove a file or directory
.Sh SYNOPSIS
.Fd #include <stdio.h>
.Ft int
@@ -48,17 +50,22 @@
.Sh DESCRIPTION
The
.Fn remove
-function
-is an alias for the
-.Xr unlink 2
-system call.
-It deletes the file referenced by
+function removes the file or directory specified by
.Fa path .
+.Pp
+If
+.Fa path
+specifies a directory,
+.Fn remove "path"
+is the equivalent of
+.Fn rmdir "path" .
+Otherwise, it is the equivalent of
+.Fn unlink "path" .
.Sh RETURN VALUES
Upon successful completion,
.Fn remove
returns 0.
-Otherwise, \-1 is returned and the global variable
+Otherwise, -1 is returned and the global variable
.Va errno
is set to indicate the error.
.Sh ERRORS
@@ -67,14 +74,17 @@ The
function
may fail and set
.Va errno
-for any of the errors specified for the routine
-.Xr unlink 2 ,
-.Xr rmdir 2 .
+for any of the errors specified for the routines
+.Xr rmdir 2
+or
+.Xr unlink 2 .
.Sh SEE ALSO
-.Xr unlink 2 ,
-.Xr rmdir 2 .
+.Xr rmdir 2 ,
+.Xr unlink 2 .
.Sh STANDARDS
The
.Fn remove
function conforms to
-.St -ansiC .
+.St -ansiC
+and
+.St -xpg4.2 .
diff --git a/lib/libc/stdio/remove.c b/lib/libc/stdio/remove.c
index 915149bc032..556925c7bf7 100644
--- a/lib/libc/stdio/remove.c
+++ b/lib/libc/stdio/remove.c
@@ -1,3 +1,5 @@
+/* $OpenBSD: remove.c,v 1.4 1997/10/08 05:26:38 millert Exp $ */
+
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -35,19 +37,24 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: remove.c,v 1.3 1996/10/28 04:55:25 tholo Exp $";
+#if 0
+static char sccsid[] = "@(#)remove.c 8.1 (Berkeley) 6/4/93";
+#else
+static char rcsid[] = "$OpenBSD: remove.c,v 1.4 1997/10/08 05:26:38 millert Exp $";
+#endif
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
+int
remove(file)
const char *file;
{
struct stat st;
- if (stat(file, &st) < 0)
+ if (lstat(file, &st) < 0)
return (-1);
if (S_ISDIR(st.st_mode))
return (rmdir(file));