#include #include #include #include #include #include int main(int argc, char **argv) { int fd, length; off_t FileLength, position; char buf[1024]; if (argc != 4){ printf("Usage: fileseek <#bytes>\n"); exit (-1); } if ((fd = open(argv[1], O_RDONLY)) < 0) { perror(argv[1]); exit(1); } position = atoi(argv[2]); length = atoi(argv[3]); FileLength = lseek(fd, 0, SEEK_END); printf("File Length %d\n", FileLength); if ((position+length) > FileLength){ printf("exceeds file limit\n"); exit(0); } lseek(fd, position, SEEK_SET); read (fd, buf, length); write (1, buf, length); }