freebsd-5-update-20030213
[openafs.git] / src / pinstall / install.c
index aa4297c..abe38f5 100644 (file)
@@ -1,6 +1,13 @@
-/***********************************************************
-               Copyright IBM Corporation 1987
+/*
+ * Copyright 2000, International Business Machines Corporation and others.
+ * All Rights Reserved.
+ * 
+ * This software has been released under the terms of the IBM Public
+ * License.  For details, see the LICENSE file in the top-level source
+ * directory or online at http://www.openafs.org/dl/license10.html
+ */
 
+/*
                       All Rights Reserved
 
 Permission to use, copy, modify, and distribute this software and its 
@@ -21,9 +28,6 @@ SOFTWARE.
 ******************************************************************/
 /* $ACIS: $ */
 
-#ifndef lint
-#endif
-
 /* ALSO utimes and strip the file
 
 Generic install command.  Options are:
@@ -42,7 +46,11 @@ Generic install command.  Options are:
 
 #define MAXFILES 200
 #define BUFSIZE 32768
+#include <afsconfig.h>
 #include <afs/param.h>
+
+RCSID("$Header$");
+
 #include <stdio.h>
 #include <pwd.h>
 #include <grp.h>
@@ -59,33 +67,44 @@ Generic install command.  Options are:
 #include <string.h>
 #include <elf.h>
 #else
+#ifdef AFS_DARWIN_ENV
+#include <fcntl.h>
+#include <string.h>
+#else
 #include <strings.h>
 #include <a.out.h>
 #endif
+#endif
 #ifdef AFS_HPUX_ENV
 #include <utime.h>
 #endif
+#include <unistd.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <stdlib.h>
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
+#include <stdio.h>
 
-struct stat istat, ostat;
+static struct stat istat, ostat;
+static int stripcalled = 0;
 
-extern int errno;
+#if !defined(AFS_DARWIN60_ENV) && !defined(AFS_FBSD50_ENV)
 extern int sys_nerr;
-#ifndef AFS_LINUX20_ENV
-extern char *sys_errlist[];
 #endif
-#if    defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DECOSF_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
-extern struct passwd *getpwnam();
-int stripcalled = 0;
+#if !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
+extern char *sys_errlist[];
 #endif
 
-#ifndef rindex
-extern char *rindex();   /* this should always be defined, shouldn't it? */
-#endif
+/* static prototypes */
+char *ErrorString(int aerrno);
+int stripName(char *aname);
+int atoo(register char *astr);
+
 
 #if defined(AFS_HPUX_ENV) && !defined(AFS_HPUX102_ENV)
-utimes(file,tvp)
-char *file;
-struct timeval tvp[2];
+int utimes(char *file, struct timeval tvp[2])
 {
        struct utimbuf times;
        
@@ -95,56 +114,54 @@ struct timeval tvp[2];
 }
 #endif
 
-static char *strrpbrk (s, set)
-  char *s;
-  char *set;
+static char *strrpbrk (char *s, char *set)
 {
     char sets[256];
     int  i;
 
-    bzero (sets, sizeof(sets));
-    while (*set) sets[*set++] = 1;
+    memset(sets, 0, sizeof(sets));
+    while (*set) sets[(int) *set++] = 1;
     i = strlen (s);
-    while (i > 0) if (sets[s[--i]]) return &s[i];
+    while (i > 0) if (sets[(int)s[--i]]) return &s[i];
     return 0;
 }
 
-char *ErrorString(aerrno)
-    int aerrno; {
+char *ErrorString(int aerrno)
+{
     static char tbuffer[100];
     if (aerrno < 0 || aerrno >= sys_nerr) {
        sprintf(tbuffer, "undefined error code %d", aerrno);
-       return tbuffer;
+    } else {
+       strcpy(tbuffer, sys_errlist[aerrno]);
     }
-    return sys_errlist[aerrno];
+    return tbuffer;
 }
 
-stripName(aname)
-    char *aname;
-    {if (rindex(aname, '.') == 0) return 1;
+int stripName(char *aname)
+{
+    if (strrchr(aname, '.') == 0) return 1;
     else return 0;
-    }
+}
 
-atoo(astr)
-    register char *astr;
-    {register afs_int32 value;
+int atoo(register char *astr)
+{
+    register afs_int32 value;
     register char tc;
     value = 0;
-    while (tc = *astr++)
+    while ((tc = *astr++))
        {value <<= 3;
        value += tc-'0';
        }
     return value;
-    }
+}
 
-#if    defined(AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DECOSF_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
+#if    defined(AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DECOSF_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_OBSD_ENV) || defined(AFS_NBSD_ENV)
 /*
  * Implementation lifted from that for AIX 3.1, since there didn't seem to be any
  * reason why it wouldn't work.
  */
-static
-quickStrip (iname, oname, ignored, copy_only)
-char *iname, *oname; {
+static int quickStrip (char *iname, char *oname, int ignored, int copy_only)
+{
        int pid, status;
        static char *strip[] = {
                "strip", 0, 0,
@@ -164,7 +181,7 @@ char *iname, *oname; {
            case 0:                     /* child        */
                copy[1] = iname;
                copy[2] = oname;
-               execve("/bin/cp", copy, (char **)0);
+               execve("/bin/cp", copy, NULL);
                perror("/bin/cp");
                exit(1);
 
@@ -189,6 +206,7 @@ char *iname, *oname; {
                return -1;
        }
 
+#if !defined(AFS_OBSD_ENV) && !defined(AFS_NBSD_ENV)
        /*
         * done the copy, now strip if desired.
         */
@@ -204,12 +222,12 @@ char *iname, *oname; {
                strip[1] = oname;
 #ifdef AFS_SUN5_ENV
 #define        STRIP_BIN       "/usr/ccs/bin/strip"
-#elif defined(AFS_LINUX20_ENV)
+#elif defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
 #define STRIP_BIN      "/usr/bin/strip"
 #else
 #define        STRIP_BIN       "/bin/strip"
 #endif
-               execve(STRIP_BIN, strip, (char **)0);
+               execve(STRIP_BIN, strip, NULL);
                perror(STRIP_BIN);
                exit(1);
 
@@ -219,28 +237,11 @@ char *iname, *oname; {
                        return -1;
                }
        }
+#endif
 
        return status;
 }
 
-/*
- * AIXobject - lie about file type
- *
- * Input:
- *     ignored
- *
- * Returns:
- *     !0 indicating that the file in question is an XCOFF type file.
- *
- * Note:
- *     Since /bin/strip will make that call for us, we will lie so that
- *     it has a chance.
- */
-AIXobject(ignored) {
-
-       return !0;
-}
-
 #else
 #ifdef AFS_AIX_ENV
 #ifdef AFS_AIX32_ENV
@@ -248,9 +249,8 @@ AIXobject(ignored) {
  * whoa! back up and be a little more rational (every little bit helps in
  * aix_31).
  */
-static
-quickStrip (iname, oname, ignored, copy_only)
-char *iname, *oname; {
+static int quickStrip (char *iname, char *oname, int ignored, int copy_only)
+{
        int pid, status;
        static char *strip[] = {
                "strip", 0, 0,
@@ -322,31 +322,12 @@ char *iname, *oname; {
        return status;
 }
 
-/*
- * AIXobject - lie about file type
- *
- * Input:
- *     ignored
- *
- * Returns:
- *     !0 indicating that the file in question is an XCOFF type file.
- *
- * Note:
- *     Since /bin/strip will make that call for us, we will lie so that
- *     it has a chance.
- */
-AIXobject(ignored) {
-
-       return !0;
-}
 #endif /* AFS_AIX32_ENV        */
 #else  /* !AFS_AIX_ENV         */
 
 #ifdef mips
 #include "sex.h"
-int quickStrip(fd, asize)
-int fd;        /* file descriptor */
-afs_int32 asize; /* ignored */
+int quickStrip(int fd, afs_int32 asize)
 {
     FILHDR fheader;
     int dum, newlen;
@@ -398,10 +379,8 @@ afs_int32 asize; /* ignored */
     return 0;
 }
 #else /* !mips */
-static int quickStrip (afd, asize)
-    int afd;
-    afs_int32 asize; {
-
+static int quickStrip (int afd, afs_int32 asize)
+{
     int n, bytesLeft;
     struct exec buf;
     struct exec *head;
@@ -439,16 +418,14 @@ static int quickStrip (afd, asize)
 
 #include "AFS_component_version_number.c"
 
-main (argc, argv)
-    int argc;
-    char **argv;
+int main (int argc, char *argv[])
 {
     int setOwner, setMode, setGroup, ifd, ofd;
-    afs_int32 mode, owner, group;
+    afs_int32 mode=0, owner, group;
     struct passwd *tpw;
     struct group *tgp;
     char *fnames[MAXFILES], *newNames[MAXFILES];
-    afs_int32 rcode, code, newcode;
+    afs_int32 rcode, code;
     char *dname;
     char pname[1024];
 #if defined (AFS_HPUX_ENV)
@@ -456,6 +433,7 @@ main (argc, argv)
 #endif /* AFS_HPUX_ENV */
     char pnametmp[1024];
     int pnamelen;
+    afs_int32 newcode;
     static char diskBuffer[BUFSIZE];   /* must be static to avoid compiler bugs for large stuff */
     char myHostName[100];
     struct timeval tvp[2];
@@ -618,7 +596,7 @@ main (argc, argv)
 
     for (i=0;i<fptr;i++)
        {/* figure out name to put as entry name for file */
-       tp = rindex(fnames[i], '/');
+       tp = strrchr(fnames[i], '/');
        if (tp) newNames[i] = tp+1;
        else newNames[i] = fnames[i];
        }
@@ -664,10 +642,10 @@ main (argc, argv)
                continue;
            }
        }
-#if    defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DECOSF_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
+#if    defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DECOSF_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_OBSD_ENV) || defined(AFS_NBSD_ENV)
        stripcalled = 0;
        if (strip == 1 ||
-           (strip == -1 && ((istat.st_mode & 0111) == 0111) && stripName(newNames[i])) && AIXobject(fnames[i]))
+           ((strip == -1 && ((istat.st_mode & 0111) == 0111) && stripName(newNames[i]))))
            stripcalled = 1;
        if (!stripcalled) {
            /* Simply copy target to dest */
@@ -815,4 +793,4 @@ main (argc, argv)
       }
     /* all done now */
     exit(rcode);
-    }
+}