- if (munmap(m, map_size) == -1) {
- err(EX_IOERR, "Could not unmap input");
- }
- if (close(fd) == -1) {
- err(EX_IOERR, "Could not close input");
+ if (munmap(m, map_size) == -1) err(EX_IOERR, "Could not unmap input");
+ if (close(fd) == -1) err(EX_IOERR, "Could not close input");
+}
+
+/* Copy data from input to output until EOF is reached. */
+static void copy(FILE* input, FILE* output) {
+ for (;;) {
+ int c = fgetc(input);
+ if (c == EOF) {
+ if (ferror(input)) errx(EX_IOERR, "Could not read");
+ if (!feof(input)) errx(EX_IOERR, "Unexpected end of file");
+ break;
+ }
+ if (fputc(c, output) == EOF) errx(EX_IOERR, "Could not write");