diff options
author | Victor Wagner <wagner@atlas-kard.ru> | 2015-10-01 16:35:32 +0300 |
---|---|---|
committer | Victor Wagner <wagner@atlas-kard.ru> | 2015-10-01 16:35:32 +0300 |
commit | 13dcbd17f3c370a7005459e1b2e6470b0262d844 (patch) | |
tree | 655586454b0de8a4ec152df3493cbcab9e9705bd /gostsum.c | |
parent | 8b9013649914a2237f7f31a7bafdf44aa635f4db (diff) | |
download | gost-engine-13dcbd17f3c370a7005459e1b2e6470b0262d844.zip gost-engine-13dcbd17f3c370a7005459e1b2e6470b0262d844.tar.gz gost-engine-13dcbd17f3c370a7005459e1b2e6470b0262d844.tar.bz2 |
Fixed some problems in standalone digest utilities
Diffstat (limited to 'gostsum.c')
-rw-r--r-- | gostsum.c | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -12,6 +12,9 @@ #include <unistd.h> #include <limits.h> #include <fcntl.h> +#ifdef _WIN32 +# include <io.h> +#endif #include <string.h> #include "gosthash.h" #define BUF_SIZE 262144 @@ -74,7 +77,7 @@ int main(int argc, char **argv) init_gost_hash_ctx(&ctx, b); if (check_file) { char inhash[65], calcsum[65], filename[PATH_MAX]; - int failcount = 0, count = 0;; + int failcount = 0, count = 0, errors = 0; if (check_file == stdin && optind < argc) { check_file = fopen(argv[optind], "r"); if (!check_file) { @@ -83,10 +86,11 @@ int main(int argc, char **argv) } } while (get_line(check_file, inhash, filename)) { + count++; if (!hash_file(&ctx, filename, calcsum, open_mode)) { - exit(2); + errors ++; + continue; } - count++; if (strncmp(calcsum, inhash, 65) == 0) { if (verbose) { fprintf(stderr, "%s\tOK\n", filename); @@ -102,15 +106,26 @@ int main(int argc, char **argv) failcount++; } } + if (errors) { + fprintf(stderr, + "%s: WARNING %d of %d file(s) cannot be processed\n", + argv[0], errors, count); + + } if (verbose && failcount) { fprintf(stderr, "%s: %d of %d file(f) failed GOST hash sum check\n", argv[0], failcount, count); } - exit(failcount ? 1 : 0); + exit((failcount || errors)? 1 : 0); } if (optind == argc) { char sum[65]; +#ifdef _WIN32 + if (open_mode & O_BINARY) { + _setmode(fileno(stdin),O_BINARY); + } +#endif if (!hash_stream(&ctx, fileno(stdin), sum)) { perror("stdin"); exit(1); |