#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_RDWR); if (fd == -1) { perror("Opening the file failed"); return 1; } int newSize = 0; while (1) { char buf[256]; int cnt = read(fd, buf, 256); if (cnt <= 0) { close(fd); return 0; } char *nlPos = memchr(buf, '\n', cnt); if (!nlPos) { newSize += cnt; continue; } newSize += nlPos - buf + 1; break; }; ftruncate(fd, newSize); close(fd); return 0; }