summaryrefslogtreecommitdiff
path: root/xor-files.c
diff options
context:
space:
mode:
Diffstat (limited to 'xor-files.c')
-rw-r--r--xor-files.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/xor-files.c b/xor-files.c
index 762ad63..a8a288c 100644
--- a/xor-files.c
+++ b/xor-files.c
@@ -6,6 +6,20 @@
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
+#include <string.h>
+
+int open_file(const char *filename) {
+ int fd;
+
+ if (!strcmp(filename, "-"))
+ return STDIN_FILENO;
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ errx(1, "open(%s)", filename);
+
+ return fd;
+}
int main(int argc, char **argv) {
int fd1, fd2;
@@ -14,13 +28,8 @@ int main(int argc, char **argv) {
if (argc < 3)
errx(1, "Usage: xor-files file1 file2");
- fd1 = open(argv[1], O_RDONLY);
- if (fd1 < 0)
- errx(1, "open(%s)", argv[1]);
-
- fd2 = open(argv[2], O_RDONLY);
- if (fd2 < 0)
- errx(1, "open(%s)", argv[2]);
+ fd1 = open_file(argv[1]);
+ fd2 = open_file(argv[2]);
do {
int errno1, errno2;