Annotation of researchv10no/cmd/mk/export/fio/tstrd.c, revision 1.1

1.1     ! root        1: #include       <fio.h>
        !             2: #include       <libc.h>
        !             3: 
        !             4: main(argc, argv)
        !             5:        char **argv;
        !             6: {
        !             7:        register n, c, k;
        !             8:        int len, fd, cd;
        !             9:        char *b1, *b2, *p;
        !            10: 
        !            11:        if(argc < 2){
        !            12:                Fprint(2, "Usage: tstrd file\n");
        !            13:                exit(1);
        !            14:        }
        !            15:        len = flen(argv[1]);
        !            16:        if((fd = open(argv[1], 0)) < 0){
        !            17:                perror(argv[1]);        
        !            18:                exit(1);
        !            19:        }
        !            20:        if((b1 = malloc(len)) == 0){
        !            21:                Fprint(2, "malloc(%d) failed\n", len);
        !            22:                exit(1);
        !            23:        }
        !            24:        if(read(fd, b1, len) != len){
        !            25:                perror("read");
        !            26:                exit(1);
        !            27:        }
        !            28:        lseek(fd, 0L, 0);
        !            29:        if((b2 = malloc(len)) == 0){
        !            30:                Fprint(2, "malloc(%d) failed\n", len);
        !            31:                exit(1);
        !            32:        }
        !            33:        for(p = b2, cd = 0; cd < len;){
        !            34:                n = 1000*nrand(6) + nrand(199);
        !            35:                if(n > len-cd) n = len-cd;
        !            36:                Fprint(1, "%d getchars\n", n);
        !            37:                cd += n;
        !            38:                while(n--)
        !            39:                        *p++ = Fgetc(fd);
        !            40:                if(cd == len)
        !            41:                        continue;
        !            42:                n = 1000*nrand(12) + nrand(199);
        !            43:                if(n > len-cd) n = len-cd;
        !            44:                cd += n;
        !            45:                Fprint(1, "%d read\n", n);
        !            46:                if(Fread(fd, p, (long)n) != (long)n) break;
        !            47:                p += n;
        !            48:        }
        !            49: done:
        !            50:        if(memcmp(b1, b2, len)){
        !            51:                Fprint(2, "memcmp failed!\n");
        !            52:                exit(1);
        !            53:        }
        !            54:        Fprint(2, "tstrd: %d bytes, succeeded\n", len);
        !            55:        exit(0);
        !            56: }
        !            57: 
        !            58: #include       <sys/types.h>
        !            59: #include       <sys/stat.h>
        !            60: 
        !            61: flen(s)
        !            62:        char *s;
        !            63: {
        !            64:        struct stat sb;
        !            65:        int n;
        !            66: 
        !            67:        if(stat(s, &sb) < 0){
        !            68:                perror(s);
        !            69:                exit(1);
        !            70:        }
        !            71:        n = sb.st_size;
        !            72:        if(sizeof(int) == 2)
        !            73:                n &= 0x7FFF;
        !            74:        return(n);
        !            75: }

unix.superglobalmegacorp.com

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