Annotation of researchv10no/cmd/PDP11/11strip.c, revision 1.1.1.1

1.1       root        1: #include "a.out.h"             /*god: using pdp11 a.out fmt */
                      2: #include <signal.h>
                      3: #include <sys/types.h>
                      4: #include <sys/stat.h>
                      5: 
                      6: char   *tname;
                      7: char   *mktemp();
                      8: struct exec head;
                      9: int    a_magic[] = {A_MAGIC1, A_MAGIC2, A_MAGIC3, A_MAGIC4, 0};
                     10: int    status;
                     11: int    tf;
                     12: 
                     13: main(argc, argv)
                     14: char *argv[];
                     15: {
                     16:        register i;
                     17: 
                     18:        signal(SIGHUP, SIG_IGN);
                     19:        signal(SIGINT, SIG_IGN);
                     20:        signal(SIGQUIT, SIG_IGN);
                     21:        tname = mktemp("/tmp/sXXXXX");
                     22:        close(creat(tname, 0600));
                     23:        tf = open(tname, 2);
                     24:        if(tf < 0) {
                     25:                printf("cannot create temp file\n");
                     26:                exit(2);
                     27:        }
                     28:        if (argc == 1) {                /*god: default 11a.out */
                     29:            argv[1] = A_DOT_OUT;        /*god*/
                     30:            ++argc;                     /*god*/
                     31:        }                               /*god*/
                     32:        for(i=1; i<argc; i++) {
                     33:                strip(argv[i]);
                     34: /*god*/                /*if(status > 1)
                     35:                        break;*/        /*god: no reason to abort*/
                     36:        }
                     37:        close(tf);
                     38:        unlink(tname);
                     39:        exit(status);
                     40: }
                     41: 
                     42: strip(name)
                     43: char *name;
                     44: {
                     45:        register f;
                     46:        long size;
                     47:        int i;
                     48:        time_t tm[2];
                     49:        struct stat stbuf;
                     50: 
                     51:        tm[0] = 0;
                     52:        f = open(name, 0);
                     53:        if(f < 0) {
                     54:                printf("cannot open %s\n", name);
                     55:                status = 1;
                     56:                goto out;
                     57:        }
                     58:        fstat(f, &stbuf);
                     59:        tm[0] = stbuf.st_atime;
                     60:        tm[1] = stbuf.st_mtime;
                     61:        read(f, (char *)&head, sizeof(head));
                     62:        for(i=0;a_magic[i];i++)
                     63:                if(a_magic[i] == head.a_magic) break;
                     64:        if(a_magic[i] == 0) {
                     65:                printf("%s not in 11a.out format\n", name);     /*god*/
                     66:                status = 1;
                     67:                goto out;
                     68:        }
                     69:        if(head.a_syms == 0 && (head.a_flag&1) != 0) {
                     70:                printf("%s already stripped\n", name);
                     71:                goto out;
                     72:        }
                     73:        size = (long)head.a_text + head.a_data;
                     74:        head.a_syms = 0;
                     75:        head.a_flag |= 1;
                     76: 
                     77:        lseek(tf, (long)0, 0);
                     78:        write(tf, (char *)&head, sizeof(head));
                     79:        if(copy(name, f, tf, size)) {
                     80:                status = 1;
                     81:                goto out;
                     82:        }
                     83:        size += sizeof(head);
                     84:        close(f);
                     85:        f = creat(name, 0666);
                     86:        if(f < 0) {
                     87:                printf("%s cannot recreate\n", name);
                     88:                status = 1;
                     89:                goto out;
                     90:        }
                     91:        lseek(tf, (long)0, 0);
                     92:        if(copy(name, tf, f, size))
                     93:                status = 2;
                     94: 
                     95: out:
                     96:        close(f);
                     97:        if (tm[0])
                     98:                utime(name, tm);
                     99: }
                    100: 
                    101: copy(name, fr, to, size)
                    102: char *name;
                    103: long size;
                    104: {
                    105:        register s, n;
                    106:        char buf[512];
                    107: 
                    108:        while(size != 0) {
                    109:                s = 512;
                    110:                if(size < 512)
                    111:                        s = size;
                    112:                n = read(fr, buf, s);
                    113:                if(n != s) {
                    114:                        printf("%s unexpected eof\n", name);
                    115:                        return(1);
                    116:                }
                    117:                n = write(to, buf, s);
                    118:                if(n != s) {
                    119:                        printf("%s unexpected write eof\n", name);
                    120:                        return(1);
                    121:                }
                    122:                size -= s;
                    123:        }
                    124:        return(0);
                    125: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.