Annotation of researchv10no/cmd/odist/tar/tarf.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <string.h>
        !             3: #include <time.h>
        !             4: #include <libv.h>
        !             5: #include "tar.h"
        !             6: #include "misc.h"
        !             7: 
        !             8: int tflag;
        !             9: 
        !            10: int nerr;
        !            11: struct sub *pathsublist;
        !            12: 
        !            13: int
        !            14: filter(FILE *ifp, FILE *ofp)
        !            15: {
        !            16:        struct tarbuf buf;
        !            17:        struct tarhdr hdr;
        !            18:        char *ptr;
        !            19:        int blocks;
        !            20:        static char z[2 * TSIZE];
        !            21: 
        !            22:        if (fread(&buf, sizeof buf, 1, ifp) != 1) {
        !            23:                ++nerr;
        !            24:                fprintf(stderr, "tarf: premature eof on input\n");
        !            25:                return 0;
        !            26:        }
        !            27:        if (memcmp(&buf, z, TSIZE) == 0) {
        !            28:                if (!tflag && fwrite(z, 1, sizeof z, ofp) != sizeof z) {
        !            29:                        ++nerr;
        !            30:                        fprintf(stderr, "tarf: error writing eof header\n");
        !            31:                }
        !            32:                return 0;
        !            33:        }
        !            34:        if (thdrget(&hdr, &buf) != 0) {
        !            35:                ++nerr;
        !            36:                fprintf(stderr, "tarf: bad input header\n");
        !            37:                return 0;
        !            38:        }
        !            39:        if (!sub(&pathsublist, 1, hdr.name, TNAMEMAX)) {
        !            40:                ++nerr;
        !            41:                fprintf(stderr, "tarf: can't expand '%s'\n", hdr.name);
        !            42:                return 0;
        !            43:        }
        !            44:        if (hdr.typeflag == LNKTYPE || hdr.typeflag == SYMTYPE)
        !            45:                sub(&pathsublist, 1, hdr.linkname, TLINKMAX);
        !            46:        blocks = (hdr.size + TSIZE - 1) / TSIZE;
        !            47:        if (tflag) {
        !            48:                fprintf(ofp, "%s\n", hdr.name);
        !            49:                if (hdr.typeflag == REGTYPE)
        !            50:                        discard(ifp, blocks * TSIZE);
        !            51:        } else {
        !            52:                if (thdrput(&buf, &hdr) != 0) {
        !            53:                        ++nerr;
        !            54:                        fprintf(stderr, "tarf: error building output header\n");
        !            55:                        return 0;
        !            56:                }
        !            57:                if (fwrite(&buf, sizeof buf, 1, ofp) != 1) {
        !            58:                        ++nerr;
        !            59:                        fprintf(stderr, "tarf: error writing output header\n");
        !            60:                        return 0;
        !            61:                }
        !            62:                if (hdr.typeflag == REGTYPE)
        !            63:                        if (fpcopy(ofp, ifp, blocks * TSIZE) != blocks * TSIZE) {
        !            64:                                ++nerr;
        !            65:                                fprintf(stderr, "tarf: error copying data\n");
        !            66:                                return 0;
        !            67:                        }
        !            68:        }
        !            69:        return 1;
        !            70: }
        !            71: 
        !            72: void
        !            73: usage(void)
        !            74: {
        !            75:        fprintf(stderr, "usage: tarf [-t] [-Dold=new ...]\n");
        !            76:        exit(1);
        !            77: }
        !            78: 
        !            79: int
        !            80: main(int argc, char *argv[])
        !            81: {
        !            82:        int c;
        !            83:        char *nstr;
        !            84: 
        !            85:        prog = argv[0];
        !            86:        while ((c = getopt(argc, argv, "tD:")) != EOF)
        !            87:                switch (c) {
        !            88:                case 't':
        !            89:                        ++tflag;
        !            90:                        break;
        !            91:                case 'D':
        !            92:                        nstr = strchr(optarg, '=');
        !            93:                        if (nstr) {
        !            94:                                *nstr = '\0';
        !            95:                                addsub(&pathsublist, optarg, nstr + 1);
        !            96:                        } else
        !            97:                                usage();
        !            98:                        break;
        !            99:                default:
        !           100:                        usage();
        !           101:                        break;
        !           102:                }
        !           103:        if (argc > 1 && optind != argc)
        !           104:                usage();
        !           105:        while (filter(stdin, stdout))
        !           106:                ;
        !           107:        if (ferror(stdin) || !feof(stdin))
        !           108:                return 1;
        !           109:        return nerr ? 1 : 0;
        !           110: }

unix.superglobalmegacorp.com

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