BSD 3 development
[unix-history] / usr / src / cmd / strip.c
index 80890c9..b74747c 100644 (file)
@@ -1,10 +1,13 @@
 #include <a.out.h>
 #include <signal.h>
 #include <a.out.h>
 #include <signal.h>
+#include <pagsiz.h>
+
+#define        BUFSIZ  BSIZE
 
 char   *tname;
 char   *mktemp();
 struct exec head;
 
 char   *tname;
 char   *mktemp();
 struct exec head;
-int    a_magic[] = {A_MAGIC1, A_MAGIC2, A_MAGIC3, A_MAGIC4, 0};
+int    a_magic[] = {A_MAGIC1, A_MAGIC2, A_MAGIC3, A_MAGIC4, 0412, 0413, 0};
 int    status;
 int    tf;
 
 int    status;
 int    tf;
 
@@ -54,16 +57,18 @@ char *name;
                status = 1;
                goto out;
        }
                status = 1;
                goto out;
        }
-       if(head.a_syms == 0 && (head.a_flag&1) != 0) {
+       if ((head.a_syms == 0) && (head.a_trsize == 0) && (head.a_drsize ==0)) {
                printf("%s already stripped\n", name);
                goto out;
        }
        size = (long)head.a_text + head.a_data;
                printf("%s already stripped\n", name);
                goto out;
        }
        size = (long)head.a_text + head.a_data;
-       head.a_syms = 0;
-       head.a_flag |= 1;
+       head.a_syms = head.a_trsize = head.a_drsize = 0 ;
 
        lseek(tf, (long)0, 0);
        write(tf, (char *)&head, sizeof(head));
 
        lseek(tf, (long)0, 0);
        write(tf, (char *)&head, sizeof(head));
+       if (head.a_magic == 0412 || head.a_magic == 0413) {
+               size += PAGSIZ - sizeof (head);
+       }
        if(copy(name, f, tf, size)) {
                status = 1;
                goto out;
        if(copy(name, f, tf, size)) {
                status = 1;
                goto out;
@@ -89,11 +94,11 @@ char *name;
 long size;
 {
        register s, n;
 long size;
 {
        register s, n;
-       char buf[512];
+       char buf[BUFSIZ];
 
        while(size != 0) {
 
        while(size != 0) {
-               s = 512;
-               if(size < 512)
+               s = BUFSIZ;
+               if(size < BUFSIZ)
                        s = size;
                n = read(fr, buf, s);
                if(n != s) {
                        s = size;
                n = read(fr, buf, s);
                if(n != s) {