/* tm.c - read tape marks */ #include #include int halt = 0; void intr(); int main(int argc, char *argv[]) { int fd; static char buf[BUFSIZ * 128]; int got = 0, data = 0, mark = 0, was = -1; char *dev = "/dev/tape"; if (argc > 1) dev = argv[1]; if ((fd = open(dev, 0)) == -1){ perror(dev); return(-1); } signal(SIGINT, intr); do { got = read(fd, buf, sizeof(buf)); got = (halt)? -1: got; /* check for restarted system call */ mark = (was == 0)? mark +1: 0; data = (was > 0)? data +1: 0; if (got != was && was > 0){ printf("%-6d X %-6d\n", data, was); mark = 0; } if (got != was && was == 0){ printf("tm X %-6d\n", mark); data = 0; } was = got; } while(got != -1); close(fd); if (halt){ puts("Interupted"); } else{ fflush(stdout); perror("EOF"); } return(0); } void intr() { halt = 1; }