pwd(1), realpath(1): Split shared source file into separate ones
authorJohn Marino <draco@marino.st>
Fri, 11 Oct 2013 20:03:46 +0000 (22:03 +0200)
committerJohn Marino <draco@marino.st>
Fri, 11 Oct 2013 23:29:27 +0000 (01:29 +0200)
The realpath(1) and pwd(1) programs share the same source file using the
program name as a condition.  Let's create a dedicated directory for
realpath, duplicate the source file, then tailor both.  Not only is this
more logical, it will make maintenance easier in the (near) future.

bin/Makefile
bin/pwd/Makefile
bin/pwd/pwd.c
bin/realpath/Makefile [new file with mode: 0644]
bin/realpath/realpath.1 [moved from bin/pwd/realpath.1 with 100% similarity]
bin/realpath/realpath.c [copied from bin/pwd/pwd.c with 91% similarity]

index 8befa98..2f7b070 100644 (file)
@@ -27,6 +27,7 @@ SUBDIR= cat \
        ps \
        pwd \
        rcp \
+       realpath \
        rm \
        rmdir \
        sh \
index 4481271..2c79f74 100644 (file)
@@ -1,9 +1,5 @@
-#      @(#)Makefile    8.1 (Berkeley) 5/31/93
 # $FreeBSD: src/bin/pwd/Makefile,v 1.5.2.3 2001/08/01 05:13:30 obrien Exp $
-# $DragonFly: src/bin/pwd/Makefile,v 1.4 2005/02/06 06:16:40 okumoto Exp $
 
 PROG=  pwd
-LINKS= ${BINDIR}/pwd ${BINDIR}/realpath
-MAN=   pwd.1 realpath.1
 
 .include <bsd.prog.mk>
index 85f025e..82e8d04 100644 (file)
@@ -29,7 +29,6 @@
  * @(#) Copyright (c) 1991, 1993, 1994 The Regents of the University of California.  All rights reserved.
  * @(#)pwd.c   8.3 (Berkeley) 4/1/94
  * $FreeBSD: src/bin/pwd/pwd.c,v 1.9.2.3 2002/06/17 11:04:22 tjr Exp $
- * $DragonFly: src/bin/pwd/pwd.c,v 1.5 2005/03/05 21:58:20 liamfoy Exp $
  */
 
 #include <sys/param.h>
@@ -38,7 +37,6 @@
 
 #include <err.h>
 #include <errno.h>
-#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -53,16 +51,6 @@ main(int argc, char *argv[])
        int physical;
        int ch;
        char *p;
-       char buf[PATH_MAX];
-
-       if (strcmp(getprogname(), "realpath") == 0) {
-               if (argc != 2)
-                       usage();
-               if ((p = realpath(argv[1], buf)) == NULL)
-                       err(1, "%s", argv[1]);
-               printf("%s\n", p);
-               exit(0);
-       }
 
        physical = 1;
        while ((ch = getopt(argc, argv, "LP")) != -1)
@@ -99,10 +87,7 @@ main(int argc, char *argv[])
 static void
 usage(void)
 {
-       if (strcmp(getprogname(), "realpath") == 0)
-               fprintf(stderr, "usage: realpath [path]\n");
-       else
-               fprintf(stderr, "usage: pwd [-LP]\n");
+       fprintf(stderr, "usage: pwd [-LP]\n");
        exit(1);
 }
 
diff --git a/bin/realpath/Makefile b/bin/realpath/Makefile
new file mode 100644 (file)
index 0000000..b250f35
--- /dev/null
@@ -0,0 +1,5 @@
+# $FreeBSD: head/bin/realpath/Makefile 90523 2002-02-11 07:32:17Z mike $
+
+PROG=  realpath
+
+.include <bsd.prog.mk>
similarity index 100%
rename from bin/pwd/realpath.1
rename to bin/realpath/realpath.1
similarity index 91%
copy from bin/pwd/pwd.c
copy to bin/realpath/realpath.c
index 85f025e..f69dd03 100644 (file)
@@ -29,7 +29,6 @@
  * @(#) Copyright (c) 1991, 1993, 1994 The Regents of the University of California.  All rights reserved.
  * @(#)pwd.c   8.3 (Berkeley) 4/1/94
  * $FreeBSD: src/bin/pwd/pwd.c,v 1.9.2.3 2002/06/17 11:04:22 tjr Exp $
- * $DragonFly: src/bin/pwd/pwd.c,v 1.5 2005/03/05 21:58:20 liamfoy Exp $
  */
 
 #include <sys/param.h>
@@ -55,14 +54,12 @@ main(int argc, char *argv[])
        char *p;
        char buf[PATH_MAX];
 
-       if (strcmp(getprogname(), "realpath") == 0) {
-               if (argc != 2)
-                       usage();
-               if ((p = realpath(argv[1], buf)) == NULL)
-                       err(1, "%s", argv[1]);
-               printf("%s\n", p);
-               exit(0);
-       }
+       if (argc != 2)
+               usage();
+       if ((p = realpath(argv[1], buf)) == NULL)
+               err(1, "%s", argv[1]);
+       printf("%s\n", p);
+       exit(0);
 
        physical = 1;
        while ((ch = getopt(argc, argv, "LP")) != -1)
@@ -101,8 +98,6 @@ usage(void)
 {
        if (strcmp(getprogname(), "realpath") == 0)
                fprintf(stderr, "usage: realpath [path]\n");
-       else
-               fprintf(stderr, "usage: pwd [-LP]\n");
        exit(1);
 }