get truncated names right -- it's 15 chars, not 16
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 12 Mar 1991 02:27:49 +0000 (18:27 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 12 Mar 1991 02:27:49 +0000 (18:27 -0800)
SCCS-vsn: usr.bin/ar/ar.1 6.7
SCCS-vsn: usr.bin/ar/archive.c 5.4
SCCS-vsn: usr.bin/ar/archive.h 5.4
SCCS-vsn: usr.bin/ar/misc.c 5.4

usr/src/usr.bin/ar/ar.1
usr/src/usr.bin/ar/archive.c
usr/src/usr.bin/ar/archive.h
usr/src/usr.bin/ar/misc.c

index e0fbaf3..10ac41a 100644 (file)
@@ -6,7 +6,7 @@
 .\"
 .\" %sccs.include.redist.man%
 .\"
 .\"
 .\" %sccs.include.redist.man%
 .\"
-.\"    @(#)ar.1        6.6 (Berkeley) %G%
+.\"    @(#)ar.1        6.7 (Berkeley) %G%
 .\"
 .TH AR 1 ""
 .AT 3
 .\"
 .TH AR 1 ""
 .AT 3
@@ -118,9 +118,12 @@ New files are appended to the archive unless one of the options \-a, \-b
 or \-i is specified.
 .TP
 \-s
 or \-i is specified.
 .TP
 \-s
-Truncate file names as necessary to fit in the standard archive file
-format (which has only sixteen bytes for the name).
-This means that file names that are not unique in their first sixteen
+Truncate file names to fit in the historical archive file format.
+The historic format had sixteen bytes for the name, but historic
+implementations couldn't handle names that used the entire space,
+so this option causes file names longer than fifteen characters to
+be truncated.
+This means that file names that are not unique in their first fifteen
 characters can subsequently be confused.
 A warning message is printed to the standard error output if any file
 names are truncated.
 characters can subsequently be confused.
 A warning message is printed to the standard error output if any file
 names are truncated.
index ff91e80..ddab5cf 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)archive.c  5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)archive.c  5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -187,19 +187,21 @@ put_object(cfp, sb)
                 * a space, use extended format 1.
                 */
                lname = strlen(name);
                 * a space, use extended format 1.
                 */
                lname = strlen(name);
-               if (!(options & AR_S) && (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);
-               } else {
-                       if (lname > sizeof(hdr->ar_name)) {
-                               (void)fflush(stdout);
-                               (void)fprintf(stderr,
+               if (options & AR_S) {
+                       if (lname > OLDARMAXNAME) {
+                               (void)fflush(stdout); (void)fprintf(stderr,
                                    "ar: warning: %s truncated to %.*s\n",
                                    "ar: warning: %s truncated to %.*s\n",
-                                   name, sizeof(hdr->ar_name), name);
+                                   name, OLDARMAXNAME, name);
                                (void)fflush(stderr);
                        }
                                (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);
+               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);
index 26e214e..21b2bf8 100644 (file)
@@ -5,7 +5,7 @@
  * This code is derived from software contributed to Berkeley by
  * Hugh Smith at The University of Guelph.
  *
  * This code is derived from software contributed to Berkeley by
  * Hugh Smith at The University of Guelph.
  *
- *     @(#)archive.h   5.3 (Berkeley) %G%
+ *     @(#)archive.h   5.4 (Berkeley) %G%
  */
 
 /* Ar(1) options. */
  */
 
 /* Ar(1) options. */
@@ -68,12 +68,12 @@ typedef struct {
        } \
 }
 
        } \
 }
 
-/* Old archive format name limit. */
-#define        ARNAMEMAX       16
-
 /* Header format strings. */
 #define        HDR1    "%s%-13d%-12ld%-6u%-6u%-8o%-10ld%2s"
 #define        HDR2    "%-16.16s%-12ld%-6u%-6u%-8o%-10ld%2s"
 
 /* Header format strings. */
 #define        HDR1    "%s%-13d%-12ld%-6u%-6u%-8o%-10ld%2s"
 #define        HDR2    "%-16.16s%-12ld%-6u%-6u%-8o%-10ld%2s"
 
+#define        OLDARMAXNAME    15
+#define        HDR3    "%-16.15s%-12ld%-6u%-6u%-8o%-10ld%2s"
+
 #include <stdlib.h>
 #include <string.h>
 #include <stdlib.h>
 #include <string.h>
index 0567e32..ed81722 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)misc.c     5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)misc.c     5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -89,7 +89,7 @@ compare(dest)
        char *rname();
 
        if (options & AR_S)
        char *rname();
 
        if (options & AR_S)
-               return(!strncmp(chdr.name, rname(dest), ARNAMEMAX));
+               return(!strncmp(chdr.name, rname(dest), OLDARMAXNAME));
        return(!strcmp(chdr.name, rname(dest)));
 }
 
        return(!strcmp(chdr.name, rname(dest)));
 }