diff options
author | Marc Stevens <cr-marcstevens@users.noreply.github.com> | 2017-05-08 23:23:17 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-08 23:23:17 +0300 |
commit | 5ee29e5e3e57015800f2eb6ced4cd28dd639e6dd (patch) | |
tree | 93281856d4cc3bd84b00fcd0eb1fd374db9512fc | |
parent | 0572d8a302b1f62f25c1559b0de74908550ab2c3 (diff) | |
parent | 8ea89fd82714f7193212a984857ea42f283b204c (diff) |
Merge pull request #28 from andreasstieger/errors_stdin
some IO improvements
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | src/main.c | 15 |
2 files changed, 11 insertions, 5 deletions
@@ -51,6 +51,7 @@ Examples: ``` bin/sha1dcsum test/sha1_reducedsha_coll.bin test/shattered-1.pdf bin/sha1dcsum_partialcoll test/sha1reducedsha_coll.bin test/shattered-1.pdf +pipe_data | bin/sha1dcsum - ``` ## Library usage @@ -8,6 +8,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <errno.h> #ifndef _WIN32 #include <libgen.h> #endif @@ -45,7 +46,7 @@ int main(int argc, char** argv) if (argc < 2) { - printf("Usage: %s <file>\n", basename(argv[0])); + fprintf(stderr, "Usage: %s <file>\n", basename(argv[0])); return 1; } @@ -59,10 +60,14 @@ int main(int argc, char** argv) SHA1DCSetDetectReducedRoundCollision(&ctx2, 1); } - fd = fopen(argv[i], "rb"); + if(!strcmp(argv[i],"-")) { + fd = stdin; + } else { + fd = fopen(argv[i], "rb"); + } if (fd == NULL) { - printf("cannot open file: %s\n", argv[i]); + fprintf(stderr, "cannot open file: %s: %s\n", argv[i], strerror(errno)); return 1; } @@ -75,12 +80,12 @@ int main(int argc, char** argv) } if (ferror(fd)) { - printf("error while reading file: %s\n", argv[i]); + fprintf(stderr, "error while reading file: %s: %s\n", argv[i], strerror(errno)); return 1; } if (!feof(fd)) { - printf("not end of file?: %s\n",argv[i]); + fprintf(stderr, "not end of file?: %s: %s\n", argv[i], strerror(errno)); return 1; } |