Bug 13071

Summary: link(1) as required by Unix 98
Product: Base System Reporter: howardjp <howardjp>
Component: binAssignee: Sheldon Hearn <sheldonh>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 3.2-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.shar none

Description howardjp 1999-08-11 13:30:02 UTC
After opening my big mouth on freebsd-advocacy about how Unix 98
compliance was a worthy goal, more than one person told me to go
ahead and send in PRs with changes.  Well, here is another :)

This contains a shar of link(1).  link accepts two arguments and
runs link(2) on them thus creating a hard link.  NetBSD places 
this in /usr/sbin and puts the man page in section 8, but nothing 
in the standard dictates where it should be.  I have the man page
in section 1.  If this is inappropriate, it can be changed without
pain.  This implementation contains no NetBSD code.

How-To-Repeat: 
Irrelevant.
Comment 1 Sheldon Hearn freebsd_committer freebsd_triage 1999-09-08 15:07:01 UTC
Responsible Changed
From-To: freebsd-bugs->sheldonh

James and I are discussing PR 13070, PR 13071 and PR 13074, which are 
all related. 

Comment 2 Sheldon Hearn 1999-12-20 14:51:30 UTC
On Wed, 11 Aug 1999 08:20:58 -0400, James Howard wrote:

> This contains a shar of link(1).  link accepts two arguments and
> runs link(2) on them thus creating a hard link.  NetBSD places 
> this in /usr/sbin and puts the man page in section 8, but nothing 
> in the standard dictates where it should be.

Not only have they placed it in an odd part of the hierarchy, but I
think it's silly to make link(1) its own command anyway.  It's basically
just a value-subtracted version on ln(1).  If we make it a hardlink, it
won't chew diskspace.

Here's what I propose.

Ciao,
Sheldon.

Index: Makefile
===================================================================
RCS file: /home/ncvs/src/bin/ln/Makefile,v
retrieving revision 1.6
diff -u -d -r1.6 Makefile
--- Makefile	1999/08/27 23:14:27	1.6
+++ Makefile	1999/12/20 12:56:54
@@ -5,4 +5,7 @@
 MAN1=	ln.1
 MAN7=	symlink.7
 
+LINKS=	${BINDIR}/ln ${BINDIR}/link
+MLINKS=	ln.1 link.1
+
 .include <bsd.prog.mk>
Index: ln.1
===================================================================
RCS file: /home/ncvs/src/bin/ln/ln.1,v
retrieving revision 1.9
diff -u -d -r1.9 ln.1
--- ln.1	1999/09/11 10:06:56	1.9
+++ ln.1	1999/12/20 13:18:40
@@ -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,12 @@
 .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.
 .Sh SEE ALSO
 .Xr link 2 ,
 .Xr lstat 2 ,
@@ -138,3 +147,7 @@
 .Nm
 command appeared in
 .At v1 .
+The simplified
+.Nm link
+command conforms to
+.St -susv2 .
Index: ln.c
===================================================================
RCS file: /home/ncvs/src/bin/ln/ln.c,v
retrieving revision 1.14
diff -u -d -r1.14 ln.c
--- ln.c	1999/09/11 10:06:56	1.14
+++ ln.c	1999/12/20 14:31:11
@@ -73,7 +73,24 @@
 	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 @@
 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);
 }
Comment 3 Sheldon Hearn freebsd_committer freebsd_triage 1999-12-20 16:15:06 UTC
State Changed
From-To: open->closed

Implemented as a special case of ln(1).  Since 3.4-RELEASE is  
expected to be the last release on the RELENG_3 branch, this 
will not be merged from CURRENT.