Annotation of researchv10no/cmd/readslow.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include <sys/types.h>
                      3: #include <sys/stat.h>
                      4: 
                      5: main(argc, argv)
                      6: char **argv;
                      7: {      int i, f=0;
                      8:        int seekf = 0;
                      9:        char buf[256];
                     10:        long amtread, lseek();
                     11:        struct stat sbuf;
                     12: 
                     13:        if (argc>1 && strcmp(argv[1], "-e") == 0) {
                     14:                seekf = 1;
                     15:                argc--;
                     16:                argv++;
                     17:        }
                     18:        if (argc>1) {
                     19:                if ((f = open(argv[1], 0)) < 0) {
                     20:                        fprintf(stderr, "readslow: can't open %s\n", argv[1]);
                     21:                        exit(1);
                     22:                }
                     23:        }
                     24:        amtread = 0;
                     25:        if (seekf)
                     26:                amtread = lseek(f, 0L, 2);
                     27:        for(;;) {
                     28:                if((i=read(f,buf,256))>0) {
                     29:                        write(1,buf,i);
                     30:                        amtread += i;
                     31:                } else if (i==0) {
                     32:                        sleep(10);
                     33:                        fstat(f, &sbuf);
                     34:                        if (sbuf.st_size < amtread) {
                     35:                                printf("\n<<< file truncated -- restarting >>>\n");
                     36:                                lseek(f, 0L, 0);
                     37:                                amtread = 0;
                     38:                                continue;
                     39:                        }
                     40:                } else
                     41:                        exit(1);
                     42:        }
                     43: }

unix.superglobalmegacorp.com

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