errx(EX_USAGE, "Usage: reverse filename");
}
- reverse_file(argv[1]);
+ reverse_file(argv[1], 1);
return 0;
}
}
}
-void reverse_file(const char* input_filename) {
+void reverse_file(const char* input_filename, int output_fd) {
int fd = open(input_filename, O_RDONLY);
if (fd == -1) {
err(EX_NOINPUT, "Could not open specified file");
for (off_t p = stats.st_size - 1; p >= 0; p--) {
buf[buf_offset++] = m[p];
if (buf_offset >= BUFFER_SIZE) {
- write_all(1, buf, buf_offset);
+ write_all(output_fd, buf, buf_offset);
buf_offset = 0;
}
}
if (buf_offset) {
- write_all(1, buf, buf_offset);
+ write_all(output_fd, buf, buf_offset);
}
if (munmap(m, map_size) == -1) {
#ifndef _OVERONION_REVERSE_LIB_H
#define _OVERONION_REVERSE_LIB_H
-/* Copy the contents of input_filename to stdout backwards.
+/* Copy the contents of input_filename to output_fd backwards.
* input_filename must be a real file, not a pipe. */
-void reverse_file(const char* input_filename);
+void reverse_file(const char* input_filename, int output_fd);
#endif /* _OVERONION_REVERSE_LIB_H */