add externs, minor cleanup
[unix-history] / usr / src / usr.bin / ar / replace.c
index ecb0157..a3ace0f 100644 (file)
@@ -9,15 +9,15 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)replace.c  5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)replace.c  5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
-#include <sys/errno.h>
 #include <fcntl.h>
 #include <fcntl.h>
-#include <unistd.h>
 #include <dirent.h>
 #include <dirent.h>
+#include <errno.h>
+#include <unistd.h>
 #include <ar.h>
 #include <stdio.h>
 #include "archive.h"
 #include <ar.h>
 #include <stdio.h>
 #include "archive.h"
@@ -36,7 +36,7 @@ extern char *tname;                     /* temporary file "name" */
 replace(argv)
        char **argv;
 {
 replace(argv)
        char **argv;
 {
-       extern char *posname;           /* positioning file name */
+       extern char *posarg, *posname;  /* positioning file name */
        register char *file;
        register int afd, curfd, mods, sfd;
        struct stat sb;
        register char *file;
        register int afd, curfd, mods, sfd;
        struct stat sb;
@@ -82,13 +82,13 @@ replace(argv)
                                goto useold;
 
                        if (options & AR_V)
                                goto useold;
 
                        if (options & AR_V)
-                            (void)printf("r - %s\n", chdr.name);
+                            (void)printf("r - %s\n", file);
 
 
+                       /* Read from disk, write to an archive; pad on write */
                        SETCF(sfd, file, curfd, tname, WPAD);
                        SETCF(sfd, file, curfd, tname, WPAD);
-                       put_header(&cf, &sb);
-                       copyfile(&cf, sb.st_size);
+                       put_object(&cf, &sb);
                        (void)close(sfd);
                        (void)close(sfd);
-                       SKIP(afd, chdr.size, archive);
+                       skipobj(afd);
                        continue;
                }
 
                        continue;
                }
 
@@ -96,21 +96,21 @@ replace(argv)
                        mods = 0;
                        if (options & AR_B)
                                curfd = tfd2;
                        mods = 0;
                        if (options & AR_B)
                                curfd = tfd2;
+                       /* Read and write to an archive; pad on both. */
                        SETCF(afd, archive, curfd, tname, RPAD|WPAD);
                        SETCF(afd, archive, curfd, tname, RPAD|WPAD);
-                       put_header(&cf, (struct stat *)NULL);
-                       copyfile(&cf, chdr.size);
+                       put_object(&cf, (struct stat *)NULL);
                        if (options & AR_A)
                                curfd = tfd2;
                } else {
                        if (options & AR_A)
                                curfd = tfd2;
                } else {
+                       /* Read and write to an archive; pad on both. */
 useold:                        SETCF(afd, archive, curfd, tname, RPAD|WPAD);
 useold:                        SETCF(afd, archive, curfd, tname, RPAD|WPAD);
-                       put_header(&cf, (struct stat *)NULL);
-                       copyfile(&cf, chdr.size);
+                       put_object(&cf, (struct stat *)NULL);
                }
        }
 
        if (mods) {
                (void)fprintf(stderr, "ar: %s: archive member not found.\n",
                }
        }
 
        if (mods) {
                (void)fprintf(stderr, "ar: %s: archive member not found.\n",
-                   posname);
+                   posarg);
                 close_archive(afd);
                 return(1);
         }
                 close_archive(afd);
                 return(1);
         }
@@ -118,7 +118,7 @@ useold:                     SETCF(afd, archive, curfd, tname, RPAD|WPAD);
        /* Append any left-over arguments to the end of the after file. */
 append:        while (file = *argv++) {
                if (options & AR_V)
        /* Append any left-over arguments to the end of the after file. */
 append:        while (file = *argv++) {
                if (options & AR_V)
-                       (void)printf("a - %s\n", rname(file));
+                       (void)printf("a - %s\n", file);
                if ((sfd = open(file, O_RDONLY)) < 0) {
                        err = 1;
                        (void)fprintf(stderr, "ar: %s: %s.\n",
                if ((sfd = open(file, O_RDONLY)) < 0) {
                        err = 1;
                        (void)fprintf(stderr, "ar: %s: %s.\n",
@@ -126,16 +126,16 @@ append:   while (file = *argv++) {
                        continue;
                }
                (void)fstat(sfd, &sb);
                        continue;
                }
                (void)fstat(sfd, &sb);
+               /* Read from disk, write to an archive; pad on write. */
                SETCF(sfd, file,
                    options & (AR_A|AR_B) ? tfd1 : tfd2, tname, WPAD);
                SETCF(sfd, file,
                    options & (AR_A|AR_B) ? tfd1 : tfd2, tname, WPAD);
-               put_header(&cf, &sb);
-               copyfile(&cf, sb.st_size);
+               put_object(&cf, &sb);
                (void)close(sfd);
        }
        
        (void)lseek(afd, (off_t)SARMAG, SEEK_SET);
 
                (void)close(sfd);
        }
        
        (void)lseek(afd, (off_t)SARMAG, SEEK_SET);
 
-       SETCF(tfd1, tname, afd, archive, RPAD|WPAD);
+       SETCF(tfd1, tname, afd, archive, NOPAD);
        if (tfd1 != -1) {
                tsize = size = lseek(tfd1, (off_t)0, SEEK_CUR);
                (void)lseek(tfd1, (off_t)0, SEEK_SET);
        if (tfd1 != -1) {
                tsize = size = lseek(tfd1, (off_t)0, SEEK_CUR);
                (void)lseek(tfd1, (off_t)0, SEEK_SET);