#include #include #include #include int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Wrong argument count!\n"); return 1; } int fd = open(argv[1], O_RDONLY); if (fd == -1) { perror("Opening the file failed"); return 1; } int filesize = lseek(fd, 0, SEEK_END); char buf[256]; printf("The file has %d bytes.\nThe last %d bytes are:\n", filesize, filesize < 16 ? filesize : 16); fflush(stdout); if (filesize < 16) lseek(fd, 0, SEEK_SET); else lseek(fd, -16, SEEK_CUR); int cnt = read(fd, buf, 16); close(fd); write(1, buf, cnt); return 0; }