]> git.saurik.com Git - apple/file_cmds.git/blobdiff - install/xinstall.c
file_cmds-251.tar.gz
[apple/file_cmds.git] / install / xinstall.c
index d5b41a12d97ae6739aab3f17186a5528eb8080f2..05b650093d9ef27c01cd9d38885aa0b3daedf6af 100644 (file)
@@ -31,8 +31,9 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
 #ifndef lint
-static const char copyright[] =
+__used static const char copyright[] =
 "@(#) Copyright (c) 1987, 1993\n\
        The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
@@ -41,7 +42,7 @@ static const char copyright[] =
 #if 0
 static char sccsid[] = "From: @(#)xinstall.c   8.1 (Berkeley) 7/21/93";
 #endif
-static const char rcsid[] =
+__used static const char rcsid[] =
   "$FreeBSD: src/usr.bin/xinstall/xinstall.c,v 1.43 2001/05/30 07:08:49 ru Exp $";
 #endif /* not lint */
 
@@ -64,8 +65,10 @@ static const char rcsid[] =
 #include <unistd.h>
 #include <sysexits.h>
 #include <utime.h>
+#include <spawn.h>
 
 #ifdef __APPLE__
+#include <TargetConditionals.h>
 #include <copyfile.h>
 #endif /* __APPLE__ */
 
@@ -107,7 +110,7 @@ main(argc, argv)
 {
        struct stat from_sb, to_sb;
        mode_t *set;
-       u_long fset;
+       u_long fset = 0;
        int ch, no_target;
        u_int iflags;
        char *flags, *group, *owner, *to_name;
@@ -526,7 +529,11 @@ install(from_name, to_name, fset, flags)
        if (!devnull)
                (void)close(from_fd);
 }
-
+#if TARGET_OS_EMBEDDED
+#define BUFFER_SIZE 128*1024
+#else  /* !TARGET_OS_EMBEDDED */
+#define BUFFER_SIZE MAXBSIZE
+#endif /* TARGET_OS_EMBEDDED */
 /*
  * compare --
  *     compare two files; non-zero means files differ
@@ -562,8 +569,8 @@ compare(int from_fd, const char *from_name, size_t from_len,
                }
        out:
                if (!done_compare) {
-                       char buf1[MAXBSIZE];
-                       char buf2[MAXBSIZE];
+                       char buf1[BUFFER_SIZE];
+                       char buf2[BUFFER_SIZE];
                        int n1, n2;
 
                        rv = 0;
@@ -666,7 +673,7 @@ copy(from_fd, from_name, to_fd, to_name, size)
 {
        register int nr, nw;
        int serrno;
-       char *p, buf[MAXBSIZE];
+       char *p, buf[BUFFER_SIZE];
        int done_copy;
 
        /* Rewind file descriptors. */
@@ -717,23 +724,21 @@ void
 strip(to_name)
        char *to_name;
 {
-       int serrno, status;
-
-       switch (fork()) {
-       case -1:
-               serrno = errno;
-               (void)unlink(to_name);
-               errno = serrno;
-               err(EX_TEMPFAIL, "fork");
-       case 0:
-               execlp("strip", "strip", to_name, NULL);
-               err(EX_OSERR, "exec(strip)");
-       default:
-               if (wait(&status) == -1 || status) {
-                       (void)unlink(to_name);
-                       exit(EX_SOFTWARE);
-                       /* NOTREACHED */
+       pid_t pid;
+       int error;
+       extern char** environ;
+       char *const argv[] = { "xcrun", "strip", "-", to_name, NULL };
+       
+       if (0 == (error = posix_spawnp(&pid, "xcrun", NULL, NULL, argv, environ))) {
+               int status = 0;
+               pid_t child = waitpid(pid, &status, 0);
+               if ((child == -1) || status) {
+                       unlink(to_name);
+                       errx(EX_SOFTWARE, "child process failed: xcrun strip - %s", to_name);
                }
+       } else {
+               errno = error;
+               err(EX_OSERR, "xcrun strip - %s", to_name);
        }
 }