#include #include #include #include extern int errno; char buf[256*1024]; char buf2[256*1024]; main(ac, av) int ac; char *av[]; { int f; int i; int cnt; int errsav; if (ac < 2) { printf("tr tape file\n"); exit(2); } if ((f = open(av[1], O_RDONLY)) < 0) { perror("open tape"); exit(1); } for (i = 0;;i++) { errno = 0; buf[0] = '\0'; cnt = read(f, buf, sizeof(buf)); errsav = errno; if (cnt < sizeof(buf) && cnt >= 16) { fprintf(stderr, "count: %d buf cont: '%.16s'\n", i, buf); } if (cnt < sizeof(buf) && cnt < 16) { fprintf(stderr, "count: %d buf2 cont: '%.16s'\n", i, buf2); } if (cnt <= 0) { fprintf(stderr, "count: %d read return: %d sizeof(buf): %d errno: %d ", i, cnt, sizeof(buf), errno); errno = errsav; /* Buggy Linux perror() always destroys errno */ perror("read: cnt <= 0"); errno = errsav; /* Buggy Linux perror() always destroys errno */ exit(0); } if (cnt < sizeof(buf)) { fprintf(stderr, "count: %d read return: %d sizeof(buf): %d errno: %d ", i, cnt, sizeof(buf), errno); errno = errsav; /* Buggy Linux perror() always destroys errno */ perror("read: cnt < sizeof(buf)"); errno = errsav; /* Buggy Linux perror() always destroys errno */ } memmove(buf2, buf, sizeof(buf)); } }