Annotation of researchv10no/cmd/mk/src/t_ar.c, revision 1.1

1.1     ! root        1: #include       "mk.h"
        !             2: #include       <sys/types.h>
        !             3: #include       <sys/stat.h>
        !             4: #include       <ar.h>
        !             5: 
        !             6: static atimes();
        !             7: 
        !             8: long
        !             9: atimeof(force, name, ar, mem)
        !            10:        char *name, *ar, *mem;
        !            11: {
        !            12:        struct stat sbuf;
        !            13:        Symtab *sym;
        !            14: 
        !            15:        if(stat(ar, &sbuf) < 0)
        !            16:                sbuf.st_mtime = 0;
        !            17:        if(sym = symlook(ar, S_AGG, (char *)0)){
        !            18:                if(force || (sbuf.st_mtime > (long)sym->value)){
        !            19:                        atimes(ar);
        !            20:                        symlook(ar, S_AGG, ar)->value = (char *)sbuf.st_mtime;
        !            21:                }
        !            22:        } else {
        !            23:                atimes(ar);
        !            24:                symlook(strdup(ar), S_AGG, ar)->value = (char *)sbuf.st_mtime;
        !            25:        }
        !            26:        if(sym = symlook(name, S_TIME, (char *)0))
        !            27:                sbuf.st_mtime = (long)sym->value;
        !            28:        else
        !            29:                sbuf.st_mtime = 0;
        !            30:        return((long)sbuf.st_mtime);
        !            31: }
        !            32: 
        !            33: void
        !            34: atouch(name, ar, mem)
        !            35:        char *name, *ar, *mem;
        !            36: {
        !            37:        int fd;
        !            38:        struct ar_hdr hdr;
        !            39:        char *s;
        !            40:        long t;
        !            41:        char buf[NAMEBLOCK];
        !            42: 
        !            43:        strcpy(buf, mem);
        !            44: #ifdef SYSV
        !            45:        strcat(buf, "/");
        !            46: #endif
        !            47:        if((fd = open(ar, 2)) < 0){
        !            48:                if((fd = creat(ar, 0666)) < 0){
        !            49:                        perror(ar);
        !            50:                        Exit();
        !            51:                }
        !            52:                write(fd, ARMAG, SARMAG);
        !            53:        }
        !            54:        if(symlook(name, S_TIME, (char *)0)){
        !            55:                /* hoon off and change it in situ */
        !            56:                lseek(fd, (long)SARMAG, 0);
        !            57:                while(read(fd, (char *)&hdr, sizeof(hdr)) == sizeof(hdr)){
        !            58:                        for(s = &hdr.ar_name[sizeof(hdr.ar_name)]; *--s == ' ';);
        !            59:                        s[1] = 0;
        !            60:                        if(strcmp(buf, hdr.ar_name) == 0){
        !            61:                                t = sizeof(hdr.ar_name)-sizeof(hdr);
        !            62:                                lseek(fd, t, 1);
        !            63:                                fprint(fd, "%-12ld", time((long *)0));
        !            64:                                break;
        !            65:                        }
        !            66:                        t = atol(hdr.ar_size);
        !            67: #ifdef CRAY
        !            68:                        t = (t+7)&~7;
        !            69:                        t -= sizeof(hdr)-60;
        !            70: #else
        !            71:                        if(t&01) t++;
        !            72: #endif
        !            73:                        lseek(fd, t, 1);
        !            74:                }
        !            75:        } else {
        !            76:                lseek(fd, 0L, 2);
        !            77:                fprint(fd, "%-16s%-12ld%-6d%-6d%-8lo%-10ld%2s", buf, time((long *)0),
        !            78:                        getuid(), getgid(), 0100666L, 0L, ARFMAG);
        !            79:        }
        !            80:        close(fd);
        !            81: }
        !            82: 
        !            83: 
        !            84: void
        !            85: adelete(name, ar, mem)
        !            86:        char *name, *ar, *mem;
        !            87: {
        !            88:        Fprint(2, "sorry; mk doesn't know how to delete archive members yet\n");
        !            89: }
        !            90: 
        !            91: static
        !            92: atimes(ar)
        !            93:        char *ar;
        !            94: {
        !            95:        struct ar_hdr hdr;
        !            96:        long t;
        !            97:        int fd;
        !            98:        char buf[BIGBLOCK];
        !            99:        register char *s;
        !           100: 
        !           101:        if((fd = open(ar, 0)) < 0)
        !           102:                return;
        !           103:        if(read(fd, buf, SARMAG) != SARMAG){
        !           104:                close(fd);
        !           105:                return;
        !           106:        }
        !           107:        while(read(fd, (char *)&hdr, sizeof(hdr)) == sizeof(hdr)){
        !           108:                for(s = &hdr.ar_name[sizeof(hdr.ar_name)]; *--s == ' ';);
        !           109: #ifdef SYSV
        !           110:                if(*s == '/')   /* Damn you Sytem V */
        !           111:                        s--;
        !           112: #endif
        !           113:                s[1] = 0;
        !           114:                t = atol(hdr.ar_date);
        !           115:                sprint(buf, "%s(%s)", ar, hdr.ar_name);
        !           116:                symlook(strdup(buf), S_TIME, (char *)t)->value = (char *)t;
        !           117:                t = atol(hdr.ar_size);
        !           118:                if(t&01) t++;
        !           119:                lseek(fd, t, 1);
        !           120:        }
        !           121:        close(fd);
        !           122: }

unix.superglobalmegacorp.com

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