BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / xinstall / xinstall.c
index a3c03a1..2a98730 100644 (file)
@@ -2,17 +2,33 @@
  * Copyright (c) 1987 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1987 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -22,7 +38,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)xinstall.c 5.22 (Berkeley) %G%";
+static char sccsid[] = "@(#)xinstall.c 5.24 (Berkeley) 7/1/90";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -94,20 +110,8 @@ main(argc, argv)
 
        no_target = stat(to_name = argv[argc - 1], &to_sb);
        if (!no_target && (to_sb.st_mode & S_IFMT) == S_IFDIR) {
 
        no_target = stat(to_name = argv[argc - 1], &to_sb);
        if (!no_target && (to_sb.st_mode & S_IFMT) == S_IFDIR) {
-               for (; *argv != to_name; ++argv) {
-                       if (stat_from(argv, &from_sb)) {
-                               fprintf(stderr, "install: can't find %s.\n",
-                                   *argv);
-                               exit(1);
-                       }
-                       if ((from_sb.st_mode & S_IFMT) != S_IFREG) {
-                               fprintf(stderr,
-                                   "install: %s isn't a regular file.\n",
-                                   *argv);
-                               exit(1);
-                       }
+               for (; *argv != to_name; ++argv)
                        install(*argv, to_name, 1);
                        install(*argv, to_name, 1);
-               }
                exit(0);
        }
 
                exit(0);
        }
 
@@ -115,21 +119,17 @@ main(argc, argv)
        if (argc != 2)
                usage();
 
        if (argc != 2)
                usage();
 
-       if (stat_from(argv, &from_sb)) {
-               fprintf(stderr, "install: can't find %s.\n", *argv);
-               exit(1);
-       }
        if (!no_target) {
        if (!no_target) {
+               if (stat(*argv, &from_sb)) {
+                       fprintf(stderr, "install: can't find %s.\n", *argv);
+                       exit(1);
+               }
                if ((to_sb.st_mode & S_IFMT) != S_IFREG) {
                if ((to_sb.st_mode & S_IFMT) != S_IFREG) {
-                       fprintf(stderr, "install: %s isn't a regular file.\n",
-                           to_name);
+                       fprintf(stderr, "install: %s isn't a regular file.\n", to_name);
                        exit(1);
                }
                        exit(1);
                }
-               if (to_sb.st_dev == from_sb.st_dev &&
-                   to_sb.st_ino == from_sb.st_ino) {
-                       fprintf(stderr,
-                           "install: %s and %s are the same file.\n",
-                           *argv, to_name);
+               if (to_sb.st_dev == from_sb.st_dev && to_sb.st_ino == from_sb.st_ino) {
+                       fprintf(stderr, "install: %s and %s are the same file.\n", *argv, to_name);
                        exit(1);
                }
                /* unlink now... avoid ETXTBSY errors later */
                        exit(1);
                }
                /* unlink now... avoid ETXTBSY errors later */
@@ -147,11 +147,20 @@ install(from_name, to_name, isdir)
        char *from_name, *to_name;
        int isdir;
 {
        char *from_name, *to_name;
        int isdir;
 {
+       struct stat from_sb;
        int devnull, from_fd, to_fd;
        char *C, *rindex();
 
        /* if try to install NULL file to a directory, fails */
        if (isdir || strcmp(from_name, _PATH_DEVNULL)) {
        int devnull, from_fd, to_fd;
        char *C, *rindex();
 
        /* if try to install NULL file to a directory, fails */
        if (isdir || strcmp(from_name, _PATH_DEVNULL)) {
+               if (stat(from_name, &from_sb)) {
+                       fprintf(stderr, "install: can't find %s.\n", from_name);
+                       exit(1);
+               }
+               if ((from_sb.st_mode & S_IFMT) != S_IFREG) {
+                       fprintf(stderr, "install: %s isn't a regular file.\n", from_name);
+                       exit(1);
+               }
                /* build the target path */
                if (isdir) {
                        (void)sprintf(pathbuf, "%s/%s", to_name, (C = rindex(from_name, '/')) ? ++C : from_name);
                /* build the target path */
                if (isdir) {
                        (void)sprintf(pathbuf, "%s/%s", to_name, (C = rindex(from_name, '/')) ? ++C : from_name);
@@ -197,25 +206,6 @@ install(from_name, to_name, isdir)
        }
 }
 
        }
 }
 
-/*
- * Find the location of the file to be installed.
- */
-stat_from(name, stbp)
-       char **name;
-       struct stat *stbp;
-{
-       char *newname;
-
-       newname = (char *)genbuildname(*name);
-       if (stat(newname, stbp) >= 0) {
-               *name = newname;
-               return (0);
-       }
-       if (stat(*name, stbp) < 0)
-               return (-1);
-       return (0);
-}
-
 /*
  * copy --
  *     copy from one file to another
 /*
  * copy --
  *     copy from one file to another