X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=gost12sum.c;h=f643b8bbf407ac39db738914b9c559cd170ea694;hb=a430c355a1d2eff5df6c96c7b6f928a609c2dd73;hp=71d73ebf5d3d5f966eadebfe537a3a071bd1175d;hpb=b13fa6d0cdd810841c3bbac1899f7a3b4083f23f;p=openssl-gost%2Fengine.git diff --git a/gost12sum.c b/gost12sum.c index 71d73eb..f643b8b 100644 --- a/gost12sum.c +++ b/gost12sum.c @@ -10,11 +10,20 @@ **********************************************************************/ #include #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 +# include #endif #include #include "gosthash2012.h" @@ -82,9 +91,9 @@ int main(int argc, char **argv) while ((c = getopt(argc, argv, "bxlvc::")) != -1) { switch (c) { - case 'b': - open_mode = open_mode | O_BINARY; - break; + case 'b': + open_mode = open_mode | O_BINARY; + break; case 'v': verbose = 1; break; @@ -111,7 +120,8 @@ int main(int argc, char **argv) } } if (check_file) { - char inhash[MAX_HASH_SIZE+1], calcsum[MAX_HASH_SIZE+1], filename[PATH_MAX]; + char inhash[MAX_HASH_SIZE + 1], calcsum[MAX_HASH_SIZE + 1], + filename[PATH_MAX]; int failcount = 0, count = 0;; if (check_file == stdin && optind < argc) { check_file = fopen(argv[optind], "r"); @@ -124,9 +134,9 @@ int main(int argc, char **argv) count++; if (!hash_file(&ctx, filename, calcsum, open_mode)) { errors++; - continue; + continue; } - if (!strncmp(calcsum, inhash, hashsize/4+1)) { + if (!strncmp(calcsum, inhash, hashsize / 4 + 1)) { if (verbose) { fprintf(stderr, "%s\tOK\n", filename); } @@ -172,9 +182,9 @@ int main(int argc, char **argv) } else if (optind == argc) { char sum[65]; #ifdef _WIN32 - if (open_mode & O_BINARY) { - _setmode(fileno(stdin), O_BINARY); - } + if (open_mode & O_BINARY) { + _setmode(fileno(stdin), O_BINARY); + } #endif if (!hash_stream(&ctx, fileno(stdin), sum)) { perror("stdin"); @@ -213,12 +223,12 @@ int hash_file(gost_hash_ctx * ctx, char *filename, char *sum, int mode) int hash_stream(gost_hash_ctx * ctx, int fd, char *sum) { unsigned char buffer[BUF_SIZE]; - unsigned char reverted_buffer[BUF_SIZE]; ssize_t bytes; - int i,j,k; + size_t i; + start_hash12(ctx); while ((bytes = read(fd, buffer, BUF_SIZE)) > 0) { - hash12_block(ctx, reverted_buffer, bytes); + hash12_block(ctx, buffer, bytes); } if (bytes < 0) { return 0; @@ -233,12 +243,12 @@ int hash_stream(gost_hash_ctx * ctx, int fd, char *sum) int get_line(FILE *f, char *hash, char *filename, int verbose) { int i, len; - int hashstrlen = hashsize/4; + int hashstrlen = hashsize / 4; while (!feof(f)) { if (!fgets(filename, PATH_MAX, f)) return 0; len = strlen(filename); - if (len < hashstrlen+2) { + if (len < hashstrlen + 2) { goto nextline; } if (filename[hashstrlen] != ' ') { @@ -255,11 +265,11 @@ int get_line(FILE *f, char *hash, char *filename, int verbose) hash[hashstrlen] = 0; while (filename[--len] == '\n' || filename[len] == '\r') filename[len] = 0; - memmove(filename, filename + hashstrlen+1, len - hashstrlen +1); + memmove(filename, filename + hashstrlen + 1, len - hashstrlen + 1); return 1; - nextline: + nextline: if (verbose) - printf(filename); + printf("%s\n", filename); } return 0; }