Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/cr-marcstevens/sha1collisiondetection.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Stevens <cr-marcstevens@users.noreply.github.com>2017-05-08 23:23:17 +0300
committerGitHub <noreply@github.com>2017-05-08 23:23:17 +0300
commit5ee29e5e3e57015800f2eb6ced4cd28dd639e6dd (patch)
tree93281856d4cc3bd84b00fcd0eb1fd374db9512fc
parent0572d8a302b1f62f25c1559b0de74908550ab2c3 (diff)
parent8ea89fd82714f7193212a984857ea42f283b204c (diff)
Merge pull request #28 from andreasstieger/errors_stdin
some IO improvements
-rw-r--r--README.md1
-rw-r--r--src/main.c15
2 files changed, 11 insertions, 5 deletions
diff --git a/README.md b/README.md
index fe7892e..1375770 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/src/main.c b/src/main.c
index ce3df75..e594830 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;
}