Annotation of coherent/g/usr/lib/misc/copyd.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copy data from one file to another for a length.
        !             3:  * Returns 1 on success, 0 on failure.
        !             4:  */
        !             5: #include <stdio.h>
        !             6: 
        !             7: copyd(ofp, ifp, len)
        !             8: FILE *ofp, *ifp;
        !             9: unsigned long len;
        !            10: {
        !            11:        register n, r;
        !            12:        char buf[BUFSIZ];
        !            13: 
        !            14:        for (n = ftell(ifp) % BUFSIZ; len; (len -= n), (n = 0)) {
        !            15:                if ((n = BUFSIZ - n) > len)
        !            16:                        n = len;
        !            17:                if (!(r = fread(buf, 1, n, ifp))  ||
        !            18:                    (r != fwrite(buf, 1, r, ofp)) ||
        !            19:                    (r != n))
        !            20:                        return (0);
        !            21:        }
        !            22:        return (1);
        !            23: }
        !            24: 
        !            25: #ifdef TEST
        !            26: #include <misc.h>
        !            27: 
        !            28: main(argc, argv)
        !            29: char *argv[];
        !            30: {
        !            31:        extern long atol();
        !            32: 
        !            33:        if (argc != 4)
        !            34:                fatal("test to from length");   
        !            35: 
        !            36:        if (!copyd(xopen(argv[1], "w"), xopen(argv[2], "r"), atol(argv[3])))
        !            37:                fatal("Error in copy");
        !            38: }
        !            39: #endif

unix.superglobalmegacorp.com

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