summaryrefslogtreecommitdiff
path: root/bin/rm
diff options
context:
space:
mode:
authorSheldon Hearn <sheldonh@FreeBSD.org>1999-12-20 16:13:47 +0000
committerSheldon Hearn <sheldonh@FreeBSD.org>1999-12-20 16:13:47 +0000
commitd71e172ac6b20daed039c3ac58f66430cd1561cd (patch)
treec936528e97653e7637f1bee418aaccd92da6e421 /bin/rm
parent0dba17bd7269471b89fcc50fe206e0a72f889f6a (diff)
downloadsrc-test2-d71e172ac6b20daed039c3ac58f66430cd1561cd.tar.gz
src-test2-d71e172ac6b20daed039c3ac58f66430cd1561cd.zip
Add link(1) and unlink(1) as special cases of ln(1) and rm(1)
respectively, in accordance with SUSv2. This differs from the approach taken in NetBSD, but provides less obscure error messages in at least the EISDIR case and does not take up additional disk space for new binaries. PR: 13071 PR: 13074 Requested by: James Howard <howardjp@wam.umd.edu>
Notes
Notes: svn path=/head/; revision=54895
Diffstat (limited to 'bin/rm')
-rw-r--r--bin/rm/Makefile3
-rw-r--r--bin/rm/rm.119
-rw-r--r--bin/rm/rm.c22
3 files changed, 42 insertions, 2 deletions
diff --git a/bin/rm/Makefile b/bin/rm/Makefile
index 45a5f23268f1..dcdae17fe0eb 100644
--- a/bin/rm/Makefile
+++ b/bin/rm/Makefile
@@ -4,6 +4,9 @@
PROG= rm
SRCS= rm.c stat_flags.c
+LINKS= ${BINDIR}/rm ${BINDIR}/unlink
+MLINKS= rm.1 unlink.1
+
.PATH: ${.CURDIR}/../ls
.include <bsd.prog.mk>
diff --git a/bin/rm/rm.1 b/bin/rm/rm.1
index 0c4b740f1543..a9b04af220dd 100644
--- a/bin/rm/rm.1
+++ b/bin/rm/rm.1
@@ -39,12 +39,15 @@
.Dt RM 1
.Os
.Sh NAME
-.Nm rm
+.Nm rm ,
+.Nm unlink
.Nd remove directory entries
.Sh SYNOPSIS
.Nm rm
.Op Fl dfiPRrvW
.Ar file ...
+.Nm unlink
+.Ar file
.Sh DESCRIPTION
The
.Nm
@@ -116,6 +119,16 @@ It is an error to attempt to remove the files
or
.Dq .. .
.Pp
+When the utility is called as
+.Nm unlink ,
+only one argument,
+which must not be a directory,
+may be supplied.
+No options may be supplied in this simple mode of operation,
+which simply performs an
+.Xr unlink 2
+operation using the two passed arguments.
+.Pp
The
.Nm
utility exits 0 if all of the named files or file hierarchies were removed,
@@ -198,3 +211,7 @@ A
.Nm
command appeared in
.At v1 .
+The simplified
+.Nm unlink
+command conforms to
+.St -susv2 .
diff --git a/bin/rm/rm.c b/bin/rm/rm.c
index 7d7de4be2929..a4a3c9676b0e 100644
--- a/bin/rm/rm.c
+++ b/bin/rm/rm.c
@@ -86,6 +86,24 @@ main(argc, argv)
char *argv[];
{
int ch, rflag;
+ char *p;
+
+ /*
+ * Test for the special case where the utility is called as
+ * "unlink", for which the functionality provided is greatly
+ * simplified.
+ */
+ if ((p = rindex(argv[0], '/')) == NULL)
+ p = argv[0];
+ else
+ ++p;
+ if (strcmp(p, "unlink") == 0) {
+ if (argc == 2) {
+ rm_file(&argv[1]);
+ exit(eval);
+ } else
+ usage();
+ }
Pflag = rflag = 0;
while ((ch = getopt(argc, argv, "dfiPRrvW")) != -1)
@@ -472,6 +490,8 @@ void
usage()
{
- (void)fprintf(stderr, "usage: rm [-f | -i] [-dPRrvW] file ...\n");
+ (void)fprintf(stderr, "%s\n%s\n",
+ "usage: rm [-f | -i] [-dPRrvW] file ...",
+ " unlink file");
exit(EX_USAGE);
}