Annotation of coherent/d/bin/sum.c, revision 1.1

1.1     ! root        1: 
        !             2: 
        !             3: /*
        !             4:  * sum -- generate checksum
        !             5:  */
        !             6: #include       <errno.h>
        !             7: #include       <stdio.h>
        !             8: 
        !             9: 
        !            10: #define        BUFSZ   (20*512)
        !            11: 
        !            12: 
        !            13: int    err;
        !            14: char   *filename;              /* used by error( ) */
        !            15: extern errno;
        !            16: 
        !            17: 
        !            18: main( argc, argv)
        !            19: register char  **argv;
        !            20: {
        !            21:        register int fd;
        !            22: 
        !            23:        if (*++argv == NULL) {
        !            24:                filename = "[stdin]";
        !            25:                sum( 0, (char *)0);
        !            26:        }
        !            27:        else
        !            28:                while (filename = *argv++) {
        !            29:                        if ((fd = open( filename, 0)) < 0) {
        !            30:                                error( (char *)0);
        !            31:                                continue;
        !            32:                        }
        !            33:                        sum( fd, argc>2? filename: (char *)0);
        !            34:                        close(fd);
        !            35:                }
        !            36: 
        !            37:        return (err);
        !            38: }
        !            39: 
        !            40: 
        !            41: sum( fd, file)
        !            42: int    fd;
        !            43: char   *file;
        !            44: {
        !            45:        register char   *p;
        !            46:        register        a,
        !            47:                        n;
        !            48:        long            size;
        !            49:        static char     buf[BUFSZ];
        !            50: 
        !            51:        a = 0;
        !            52:        size = 0;
        !            53: 
        !            54:        while ((n=read( fd, buf, sizeof buf)) > 0) {
        !            55:                size += n;
        !            56:                p = buf;
        !            57:                do {
        !            58:                        a += *p++;
        !            59:                } while (--n);
        !            60:        }
        !            61: 
        !            62:        if (n < 0)
        !            63:                error( errno==EIO? "read error": (char *)0);
        !            64:        printf( "%5u %2ld", a, (size+BUFSIZ-1)/BUFSIZ);
        !            65:        if (file)
        !            66:                printf( " %s", file);
        !            67:        printf( "\n");
        !            68: }
        !            69: 
        !            70: 
        !            71: error( mesg)
        !            72: char   *mesg;
        !            73: {
        !            74:        extern char     *sys_errlist[];
        !            75: 
        !            76:        fprintf( stderr, "sum: %s: %s\n", filename,
        !            77:                mesg? mesg: sys_errlist[errno]);
        !            78:        err = 1;
        !            79: }

unix.superglobalmegacorp.com

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