X-Git-Url: http://www.wagner.pp.ru/gitweb/?a=blobdiff_plain;f=gostsum.c;h=b61215c9f08cb8ab05feb7ff9e57d653967a5c1e;hb=HEAD;hp=252bd2cfed6a25c81efdb1f5997e9c0fe765f55e;hpb=02f99b2e3b46f4ff44fd5420487551d5a447c2ad;p=openssl-gost%2Fengine.git diff --git a/gostsum.c b/gostsum.c index 252bd2c..b61215c 100644 --- a/gostsum.c +++ b/gostsum.c @@ -9,9 +9,21 @@ **********************************************************************/ #include #include +#ifdef _MSC_VER +#include "getopt.h" +# ifndef PATH_MAX +# define PATH_MAX _MAX_PATH +# endif +#include +typedef SSIZE_T ssize_t; +#else #include +#endif #include #include +#ifdef _WIN32 +# include +#endif #include #include "gosthash.h" #define BUF_SIZE 262144 @@ -74,7 +86,8 @@ 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 +96,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 +116,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); @@ -138,6 +163,7 @@ int hash_file(gost_hash_ctx * ctx, char *filename, char *sum, int mode) } if (!hash_stream(ctx, fd, sum)) { perror(filename); + close(fd); return 0; } close(fd);