#include #include #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; } unlink(argv[1]); char *buf = malloc(strlen(argv[1]) + 17); sprintf(buf, "Executing stat %s\n", argv[1]); write(1, buf, strlen(buf)); system(buf + 10); struct stat sb; fstat(fd, &sb); sprintf(buf, "Link count: %zu\n", sb.st_nlink); write(1, buf, strlen(buf)); write(1, "Reading and printing the file:\n", 31); while (1) { char buf[256]; int cnt = read(fd, buf, 256); if (cnt <= 0) break; write(1, buf, cnt); } close(fd); return 0; }