Patch to add link (SUSv2) utility

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Patch to add link (SUSv2) utility

Andrés Delfino
A couple of days ago I sent a patch to @bugs to add the link (SUSv2)
utility. Now that the tree is unlocked (AFAIK), I send it again. I
revised it, including the use of __progname, usage and man page
update. Greetings!

Index: src/bin/ln/ln.1
===================================================================
RCS file: /cvs/src/bin/ln/ln.1,v
retrieving revision 1.22
diff -u -r1.22 ln.1
--- src/bin/ln/ln.1 2 Dec 2005 20:36:56 -0000 1.22
+++ src/bin/ln/ln.1 19 Sep 2006 12:58:31 -0000
@@ -37,7 +37,8 @@
 .Dt LN 1
 .Os
 .Sh NAME
-.Nm ln
+.Nm ln ,
+.Nm link
 .Nd make hard and symbolic links to files
 .Sh SYNOPSIS
 .Nm ln
@@ -48,6 +49,8 @@
 .Op Fl fs
 .Ar sourcefile ...\&
 .Op Ar targetdir
+.Nm link
+.Ar source_file Ar target_file
 .Sh DESCRIPTION
 The
 .Nm
@@ -126,6 +129,15 @@
 The
 .Nm
 utility exits 0 on success or >0 if an error occurred.
+.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 performs a
+.Xr link 2
+operation using the two passed arguments.
 .Sh EXAMPLES
 Create a symbolic link named
 .Pa /home/www
Index: src/bin/ln/ln.c
===================================================================
RCS file: /cvs/src/bin/ln/ln.c,v
retrieving revision 1.14
diff -u -r1.14 ln.c
--- src/bin/ln/ln.c 25 Apr 2006 04:38:26 -0000 1.14
+++ src/bin/ln/ln.c 19 Sep 2006 12:58:31 -0000
@@ -71,6 +71,23 @@
  struct stat sb;
  int ch, exitval;
  char *sourcedir;
+ extern char *__progname;
+
+ /*
+ * Test for the special case where the utility is called as
+ * "link", for which the functionality provided is greatly
+ * simplified.
+ */
+ if (strcmp(__progname, "link") == 0) {
+ while (getopt(argc, argv, "") != -1)
+ usage();
+ argc -= optind;
+ argv += optind;
+ if (argc != 2)
+ usage();
+ linkf = link;
+ exit(linkit(argv[0], argv[1], 0));
+ }

  while ((ch = getopt(argc, argv, "Ffhns")) != -1)
  switch (ch) {
@@ -174,7 +191,8 @@

  (void)fprintf(stderr,
     "usage: %s [-fhns] sourcefile [targetfile]\n"
-    "       %s [-fs] sourcefile ... [targetdir]\n",
-    __progname, __progname);
+    "       %s [-fs] sourcefile ... [targetdir]\n"
+    "       %s sourcefile [targetfile]\n",
+    __progname, __progname, __progname);
  exit(1);
 }

Reply | Threaded
Open this post in threaded view
|

Re: Patch to add link (SUSv2) utility

Otto Moerbeek
On Tue, 19 Sep 2006, AndrC)s wrote:

> A couple of days ago I sent a patch to @bugs to add the link (SUSv2)
> utility. Now that the tree is unlocked (AFAIK), I send it again. I
> revised it, including the use of __progname, usage and man page
> update. Greetings!

Is there any reason (apart from standard conformance) why you would
want to have this command? In other words, can you give me a real-life
example where having this command is actually useful?

I'm trying to understand why this is in SU.

        -Otto

>
> Index: src/bin/ln/ln.1
> ===================================================================
> RCS file: /cvs/src/bin/ln/ln.1,v
> retrieving revision 1.22
> diff -u -r1.22 ln.1
> --- src/bin/ln/ln.1 2 Dec 2005 20:36:56 -0000 1.22
> +++ src/bin/ln/ln.1 19 Sep 2006 12:58:31 -0000
> @@ -37,7 +37,8 @@
> .Dt LN 1
> .Os
> .Sh NAME
> -.Nm ln
> +.Nm ln ,
> +.Nm link
> .Nd make hard and symbolic links to files
> .Sh SYNOPSIS
> .Nm ln
> @@ -48,6 +49,8 @@
> .Op Fl fs
> .Ar sourcefile ...\&
> .Op Ar targetdir
> +.Nm link
> +.Ar source_file Ar target_file
> .Sh DESCRIPTION
> The
> .Nm
> @@ -126,6 +129,15 @@
> The
> .Nm
> utility exits 0 on success or >0 if an error occurred.
> +.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 performs a
> +.Xr link 2
> +operation using the two passed arguments.
> .Sh EXAMPLES
> Create a symbolic link named
> .Pa /home/www
> Index: src/bin/ln/ln.c
> ===================================================================
> RCS file: /cvs/src/bin/ln/ln.c,v
> retrieving revision 1.14
> diff -u -r1.14 ln.c
> --- src/bin/ln/ln.c 25 Apr 2006 04:38:26 -0000 1.14
> +++ src/bin/ln/ln.c 19 Sep 2006 12:58:31 -0000
> @@ -71,6 +71,23 @@
> struct stat sb;
> int ch, exitval;
> char *sourcedir;
> + extern char *__progname;
> +
> + /*
> + * Test for the special case where the utility is called as
> + * "link", for which the functionality provided is greatly
> + * simplified.
> + */
> + if (strcmp(__progname, "link") == 0) {
> + while (getopt(argc, argv, "") != -1)
> + usage();
> + argc -= optind;
> + argv += optind;
> + if (argc != 2)
> + usage();
> + linkf = link;
> + exit(linkit(argv[0], argv[1], 0));
> + }
>
> while ((ch = getopt(argc, argv, "Ffhns")) != -1)
> switch (ch) {
> @@ -174,7 +191,8 @@
>
> (void)fprintf(stderr,
>    "usage: %s [-fhns] sourcefile [targetfile]\n"
> -    "       %s [-fs] sourcefile ... [targetdir]\n",
> -    __progname, __progname);
> +    "       %s [-fs] sourcefile ... [targetdir]\n"
> +    "       %s sourcefile [targetfile]\n",
> +    __progname, __progname, __progname);
> exit(1);
> }

Reply | Threaded
Open this post in threaded view
|

Re: Patch to add link (SUSv2) utility

Andrés Delfino
On 9/20/06, Otto Moerbeek <[hidden email]> wrote:
> Is there any reason (apart from standard conformance) why you would
> want to have this command? In other words, can you give me a real-life
> example where having this command is actually useful?

No.