#include #include #include int main(int argc, char **argv) { setvbuf(stdout, NULL, _IONBF, 0); if (argc != 2) { fprintf(stderr, "Wrong argument count!\n"); return 1; } int fd = open(argv[1], O_RDWR); if (fd == -1) { perror("Opening the file failed"); return 1; } int cnt, pos; char buf[16]; pos = lseek(fd, 0, SEEK_CUR); printf("Pos upon opening: %d\n", pos); cnt = read(fd, buf, 16); printf("First 16 bytes: "); write(1, buf, cnt); pos = lseek(fd, 0, SEEK_CUR); printf("\nPos before 16-byte write: %d\n", pos); cnt = write(fd, "Kilroy was here ", 16); pos = lseek(fd, 0, SEEK_CUR); printf("Pos after 16-byte write: %d\n", pos); close(fd); return 0; }