diff options
-rw-r--r-- | bin/ln/Makefile | 3 | ||||
-rw-r--r-- | bin/ln/ln.1 | 18 | ||||
-rw-r--r-- | bin/ln/ln.c | 24 | ||||
-rw-r--r-- | bin/rm/Makefile | 3 | ||||
-rw-r--r-- | bin/rm/rm.1 | 19 | ||||
-rw-r--r-- | bin/rm/rm.c | 22 |
6 files changed, 83 insertions, 6 deletions
diff --git a/bin/ln/Makefile b/bin/ln/Makefile index b177ea8..bfbcef8 100644 --- a/bin/ln/Makefile +++ b/bin/ln/Makefile @@ -5,4 +5,7 @@ PROG= ln MAN1= ln.1 MAN7= symlink.7 +LINKS= ${BINDIR}/ln ${BINDIR}/link +MLINKS= ln.1 link.1 + .include <bsd.prog.mk> diff --git a/bin/ln/ln.1 b/bin/ln/ln.1 index ea9458f..bc8546c 100644 --- a/bin/ln/ln.1 +++ b/bin/ln/ln.1 @@ -39,7 +39,8 @@ .Dt LN 1 .Os BSD 4 .Sh NAME -.Nm ln +.Nm ln , +.Nm link .Nd make links .Sh SYNOPSIS .Nm ln @@ -50,6 +51,8 @@ .Op Fl fsv .Ar source_file ... .Op target_dir +.Nm link +.Ar source_file Ar target_file .Sh DESCRIPTION The .Nm @@ -122,6 +125,15 @@ makes links in .Ar target_dir to all the named source files. The links made will have the same name as the files being linked to. +.Pp +When the utility is called as +.Nm link , +exactly two arguments must be supplied, +neither of which may specify a directory. +No options may be supplied in this simple mode of operation, +which simply performs a +.Xr link 2 +operation using the two passed arguments. .Sh SEE ALSO .Xr link 2 , .Xr lstat 2 , @@ -138,3 +150,7 @@ An .Nm command appeared in .At v1 . +The simplified +.Nm link +command conforms to +.St -susv2 . diff --git a/bin/ln/ln.c b/bin/ln/ln.c index 48dbeae..dc2db0f 100644 --- a/bin/ln/ln.c +++ b/bin/ln/ln.c @@ -73,7 +73,24 @@ main(argc, argv) extern int optind; struct stat sb; int ch, exitval; - char *sourcedir; + char *p, *sourcedir; + + /* + * Test for the special case where the utility is called as + * "link", for which the functionality provided is greatly + * simplified. + */ + if ((p = rindex(argv[0], '/')) == NULL) + p = argv[0]; + else + ++p; + if (strcmp(p, "link") == 0) { + if (argc == 3) { + linkf = link; + exit(linkit(argv[1], argv[2], 0)); + } else + usage(); + } while ((ch = getopt(argc, argv, "fsv")) != -1) switch (ch) { @@ -167,8 +184,9 @@ linkit(target, source, isdir) void usage() { - (void)fprintf(stderr, "%s\n%s\n", + (void)fprintf(stderr, "%s\n%s\n%s\n", "usage: ln [-fsv] file1 file2", - " ln [-fsv] file ... directory"); + " ln [-fsv] file ... directory", + " link file1 file2"); exit(1); } diff --git a/bin/rm/Makefile b/bin/rm/Makefile index 45a5f23..dcdae17 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 0c4b740..a9b04af 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 7d7de4b..a4a3c96 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); } |