- reverse_file(input_file, fd);
- if (close(fd) == -1) err(EX_IOERR, "Couldn't close temporary file");
+ FILE* f = fdopen(fd, "w");
+ if (f == NULL) err(EX_IOERR, "Couldn't open temporary file");
+ reverse_file(input_file, f);
+ if (fclose(f) == EOF) err(EX_IOERR, "Couldn't close temporary file");