BSD 4_4_Lite1 release
[unix-history] / usr / src / usr.bin / ar / archive.c
index 96e6db1..10897d9 100644 (file)
@@ -1,5 +1,5 @@
 /*-
 /*-
- * Copyright (c) 1990, 1993
+ * Copyright (c) 1990, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)archive.c  8.1 (Berkeley) 6/6/93";
+static char sccsid[] = "@(#)archive.c  8.3 (Berkeley) 4/2/94";
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <dirent.h>
+
 #include <ar.h>
 #include <ar.h>
+#include <dirent.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
+
 #include "archive.h"
 #include "extern.h"
 
 #include "archive.h"
 #include "extern.h"
 
-extern CHDR chdr;                      /* converted header */
-extern char *archive;                  /* archive name */
-
 typedef struct ar_hdr HDR;
 static char hb[sizeof(HDR) + 1];       /* real header */
 
 typedef struct ar_hdr HDR;
 static char hb[sizeof(HDR) + 1];       /* real header */
 
+int
 open_archive(mode)
        int mode;
 {
 open_archive(mode)
        int mode;
 {
@@ -69,8 +70,7 @@ open_archive(mode)
                if ((fd = open(archive, mode, DEFFILEMODE)) >= 0) {
                        /* POSIX.2 puts create message on stderr. */
                        if (!(options & AR_C))
                if ((fd = open(archive, mode, DEFFILEMODE)) >= 0) {
                        /* POSIX.2 puts create message on stderr. */
                        if (!(options & AR_C))
-                               (void)fprintf(stderr,
-                                   "ar: creating archive %s.\n", archive);
+                               warnx("creating archive %s", archive);
                        created = 1;
                        goto opened;
                }
                        created = 1;
                        goto opened;
                }
@@ -103,19 +103,20 @@ opened:   if (flock(fd, LOCK_EX|LOCK_NB) && errno != EOPNOTSUPP)
                        badfmt();
        } else if (write(fd, ARMAG, SARMAG) != SARMAG)
                error(archive);
                        badfmt();
        } else if (write(fd, ARMAG, SARMAG) != SARMAG)
                error(archive);
-       return(fd);
+       return (fd);
 }
 
 void
 close_archive(fd)
        int fd;
 {
 }
 
 void
 close_archive(fd)
        int fd;
 {
+
        (void)close(fd);                        /* Implicit unlock. */
 }
 
 /* Convert ar header field to an integer. */
 #define        AR_ATOI(from, to, len, base) { \
        (void)close(fd);                        /* Implicit unlock. */
 }
 
 /* Convert ar header field to an integer. */
 #define        AR_ATOI(from, to, len, base) { \
-       bcopy(from, buf, len); \
+       memmove(buf, from, len); \
        buf[len] = '\0'; \
        to = strtol(buf, (char **)NULL, base); \
 }
        buf[len] = '\0'; \
        to = strtol(buf, (char **)NULL, base); \
 }
@@ -124,18 +125,18 @@ close_archive(fd)
  * get_arobj --
  *     read the archive header for this member
  */
  * get_arobj --
  *     read the archive header for this member
  */
+int
 get_arobj(fd)
        int fd;
 {
        struct ar_hdr *hdr;
 get_arobj(fd)
        int fd;
 {
        struct ar_hdr *hdr;
-       register int len, nr;
-       register char *p;
-       char buf[20];
+       int len, nr;
+       char *p, buf[20];
 
        nr = read(fd, hb, sizeof(HDR));
        if (nr != sizeof(HDR)) {
                if (!nr)
 
        nr = read(fd, hb, sizeof(HDR));
        if (nr != sizeof(HDR)) {
                if (!nr)
-                       return(0);
+                       return (0);
                if (nr < 0)
                        error(archive);
                badfmt();
                if (nr < 0)
                        error(archive);
                badfmt();
@@ -177,13 +178,13 @@ get_arobj(fd)
                chdr.size -= len;
        } else {
                chdr.lname = 0;
                chdr.size -= len;
        } else {
                chdr.lname = 0;
-               bcopy(hdr->ar_name, chdr.name, sizeof(hdr->ar_name));
+               memmove(chdr.name, hdr->ar_name, sizeof(hdr->ar_name));
 
                /* Strip trailing spaces, null terminate. */
                for (p = chdr.name + sizeof(hdr->ar_name) - 1; *p == ' '; --p);
                *++p = '\0';
        }
 
                /* Strip trailing spaces, null terminate. */
                for (p = chdr.name + sizeof(hdr->ar_name) - 1; *p == ' '; --p);
                *++p = '\0';
        }
-       return(1);
+       return (1);
 }
 
 static int already_written;
 }
 
 static int already_written;
@@ -192,12 +193,13 @@ static int already_written;
  * put_arobj --
  *     Write an archive member to a file.
  */
  * put_arobj --
  *     Write an archive member to a file.
  */
+void
 put_arobj(cfp, sb)
        CF *cfp;
        struct stat *sb;
 {
 put_arobj(cfp, sb)
        CF *cfp;
        struct stat *sb;
 {
-       register int lname;
-       register char *name;
+       int lname;
+       char *name;
        struct ar_hdr *hdr;
        off_t size;
 
        struct ar_hdr *hdr;
        off_t size;
 
@@ -219,8 +221,7 @@ put_arobj(cfp, sb)
                if (options & AR_TR) {
                        if (lname > OLDARMAXNAME) {
                                (void)fflush(stdout);
                if (options & AR_TR) {
                        if (lname > OLDARMAXNAME) {
                                (void)fflush(stdout);
-                               (void)fprintf(stderr,
-                                   "ar: warning: %s truncated to %.*s\n",
+                               warnx("warning: %s truncated to %.*s\n",
                                    name, OLDARMAXNAME, name);
                                (void)fflush(stderr);
                        }
                                    name, OLDARMAXNAME, name);
                                (void)fflush(stderr);
                        }
@@ -228,7 +229,7 @@ put_arobj(cfp, sb)
                            sb->st_uid, sb->st_gid, sb->st_mode, sb->st_size,
                            ARFMAG);
                        lname = 0;
                            sb->st_uid, sb->st_gid, sb->st_mode, sb->st_size,
                            ARFMAG);
                        lname = 0;
-               } else if (lname > sizeof(hdr->ar_name) || index(name, ' '))
+               } else if (lname > sizeof(hdr->ar_name) || strchr(name, ' '))
                        (void)sprintf(hb, HDR1, AR_EFMT1, lname,
                            sb->st_mtimespec.ts_sec, sb->st_uid, sb->st_gid,
                            sb->st_mode, sb->st_size + lname, ARFMAG);
                        (void)sprintf(hb, HDR1, AR_EFMT1, lname,
                            sb->st_mtimespec.ts_sec, sb->st_uid, sb->st_gid,
                            sb->st_mode, sb->st_size + lname, ARFMAG);
@@ -270,13 +271,14 @@ put_arobj(cfp, sb)
  *     because 16-bit word addressed copies were faster?)  Anyhow, it should
  *     have been ripped out long ago.
  */
  *     because 16-bit word addressed copies were faster?)  Anyhow, it should
  *     have been ripped out long ago.
  */
+void
 copy_ar(cfp, size)
        CF *cfp;
        off_t size;
 {
        static char pad = '\n';
 copy_ar(cfp, size)
        CF *cfp;
        off_t size;
 {
        static char pad = '\n';
-       register off_t sz;
-       register int from, nr, nw, off, to;
+       off_t sz;
+       int from, nr, nw, off, to;
        char buf[8*1024];
        
        if (!(sz = size))
        char buf[8*1024];
        
        if (!(sz = size))