char* temp_filename = strdup("/tmp/reverse_test.XXXXXX");
int fd = mkstemp(temp_filename);
if (fd == -1) err(EX_IOERR, "Couldn't make a temporary file");
- 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");
return temp_filename;
}