date and time created 91/04/03 11:08:05 by bostic
[unix-history] / usr / src / usr.bin / ar / archive.c
index 028fd2d..1d4e7f5 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)archive.c  5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)archive.c  5.7 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -20,7 +20,10 @@ static char sccsid[] = "@(#)archive.c        5.2 (Berkeley) %G%";
 #include <dirent.h>
 #include <ar.h>
 #include <stdio.h>
 #include <dirent.h>
 #include <ar.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include "archive.h"
 #include "archive.h"
+#include "extern.h"
 
 extern CHDR chdr;                      /* converted header */
 extern char *archive;                  /* archive name */
 
 extern CHDR chdr;                      /* converted header */
 extern char *archive;                  /* archive name */
@@ -77,11 +80,11 @@ opened:     if (flock(fd, LOCK_EX|LOCK_NB) && errno != EOPNOTSUPP)
        return(fd);
 }
 
        return(fd);
 }
 
+void
 close_archive(fd)
        int fd;
 {
 close_archive(fd)
        int fd;
 {
-       (void)flock(fd, LOCK_UN);
-       (void)close(fd);
+       (void)close(fd);                        /* Implicit unlock. */
 }
 
 /* Convert ar header field to an integer. */
 }
 
 /* Convert ar header field to an integer. */
@@ -92,10 +95,10 @@ close_archive(fd)
 }
 
 /*
 }
 
 /*
- * get_header --
+ * get_arobj --
  *     read the archive header for this member
  */
  *     read the archive header for this member
  */
-get_header(fd)
+get_arobj(fd)
        int fd;
 {
        struct ar_hdr *hdr;
        int fd;
 {
        struct ar_hdr *hdr;
@@ -159,10 +162,10 @@ get_header(fd)
 static int already_written;
 
 /*
 static int already_written;
 
 /*
- * put_object --
+ * put_arobj --
  *     Write an archive member to a file.
  */
  *     Write an archive member to a file.
  */
-put_object(cfp, sb)
+put_arobj(cfp, sb)
        CF *cfp;
        struct stat *sb;
 {
        CF *cfp;
        struct stat *sb;
 {
@@ -170,7 +173,6 @@ put_object(cfp, sb)
        register char *name;
        struct ar_hdr *hdr;
        off_t size;
        register char *name;
        struct ar_hdr *hdr;
        off_t size;
-       char *rname();
 
        /*
         * If passed an sb structure, reading a file from disk.  Get stat(2)
 
        /*
         * If passed an sb structure, reading a file from disk.  Get stat(2)
@@ -182,12 +184,27 @@ put_object(cfp, sb)
                name = rname(cfp->rname);
                (void)fstat(cfp->rfd, sb);
 
                name = rname(cfp->rname);
                (void)fstat(cfp->rfd, sb);
 
-               if ((lname = strlen(name)) > sizeof(hdr->ar_name) ||
-                   index(name, ' ')) {
+               /*
+                * If not truncating names and the name is too long or contains
+                * a space, use extended format 1.
+                */
+               lname = strlen(name);
+               if (options & AR_TR) {
+                       if (lname > OLDARMAXNAME) {
+                               (void)fflush(stdout);
+                               (void)fprintf(stderr,
+                                   "ar: warning: %s truncated to %.*s\n",
+                                   name, OLDARMAXNAME, name);
+                               (void)fflush(stderr);
+                       }
+                       (void)sprintf(hb, HDR3, name, sb->st_mtime, sb->st_uid,
+                           sb->st_gid, sb->st_mode, sb->st_size, ARFMAG);
+                       lname = 0;
+               } else if (lname > sizeof(hdr->ar_name) || index(name, ' '))
                        (void)sprintf(hb, HDR1, AR_EFMT1, lname, sb->st_mtime,
                            sb->st_uid, sb->st_gid, sb->st_mode,
                            sb->st_size + lname, ARFMAG);
                        (void)sprintf(hb, HDR1, AR_EFMT1, lname, sb->st_mtime,
                            sb->st_uid, sb->st_gid, sb->st_mode,
                            sb->st_size + lname, ARFMAG);
-               else {
+               else {
                        lname = 0;
                        (void)sprintf(hb, HDR2, name, sb->st_mtime, sb->st_uid,
                            sb->st_gid, sb->st_mode, sb->st_size, ARFMAG);
                        lname = 0;
                        (void)sprintf(hb, HDR2, name, sb->st_mtime, sb->st_uid,
                            sb->st_gid, sb->st_mode, sb->st_size, ARFMAG);
@@ -206,12 +223,12 @@ put_object(cfp, sb)
                        error(cfp->wname);
                already_written = lname;
        }
                        error(cfp->wname);
                already_written = lname;
        }
-       copyfile(cfp, size);
+       copy_ar(cfp, size);
        already_written = 0;
 }
 
 /*
        already_written = 0;
 }
 
 /*
- * copyfile --
+ * copy_ar --
  *     Copy size bytes from one file to another - taking care to handle the
  *     extra byte (for odd size files) when reading archives and writing an
  *     extra byte if necessary when adding files to archive.  The length of
  *     Copy size bytes from one file to another - taking care to handle the
  *     extra byte (for odd size files) when reading archives and writing an
  *     extra byte if necessary when adding files to archive.  The length of
@@ -224,7 +241,7 @@ put_object(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.
  */
-copyfile(cfp, size)
+copy_ar(cfp, size)
        CF *cfp;
        off_t size;
 {
        CF *cfp;
        off_t size;
 {
@@ -262,10 +279,11 @@ copyfile(cfp, size)
 }
 
 /*
 }
 
 /*
- * skipobj -
+ * skip_arobj -
  *     Skip over an object -- taking care to skip the pad bytes.
  */
  *     Skip over an object -- taking care to skip the pad bytes.
  */
-skipobj(fd)
+void
+skip_arobj(fd)
        int fd;
 {
        off_t len;
        int fd;
 {
        off_t len;