Browse Source

better output on stderr

Steffen Jaeckel 8 years ago
parent
commit
85c2186ae6
1 changed files with 4 additions and 4 deletions
  1. 4 4
      demos/hashsum.c

+ 4 - 4
demos/hashsum.c

@@ -112,7 +112,7 @@ static void check_file(int argn, int argc, char **argv)
                tries++;
                tries++;
                w = sizeof(is_buffer);
                w = sizeof(is_buffer);
                if ((err = hash_file(x, space, is_buffer, &w)) != CRYPT_OK) {
                if ((err = hash_file(x, space, is_buffer, &w)) != CRYPT_OK) {
-                  fprintf(stderr, "File hash error: %s: %s\n", space, error_to_string(err));
+                  fprintf(stderr, "%s: File hash error: %s: %s\n", hashsum, space, error_to_string(err));
 ERR:
 ERR:
                   fclose(f);
                   fclose(f);
                   exit(EXIT_FAILURE);
                   exit(EXIT_FAILURE);
@@ -208,7 +208,7 @@ int main(int argc, char **argv)
                }
                }
             }
             }
             if (idx == -1) {
             if (idx == -1) {
-               fprintf(stderr, "Invalid hash (%s) specified on command line.\n", argv[2]);
+               fprintf(stderr, "%s: Unrecognized algorithm\n", hashsum);
                die(EXIT_FAILURE);
                die(EXIT_FAILURE);
             }
             }
             argn++;
             argn++;
@@ -233,7 +233,7 @@ int main(int argc, char **argv)
    if (argc == argn) {
    if (argc == argn) {
       w = sizeof(hash_buffer);
       w = sizeof(hash_buffer);
       if ((err = hash_filehandle(idx, stdin, hash_buffer, &w)) != CRYPT_OK) {
       if ((err = hash_filehandle(idx, stdin, hash_buffer, &w)) != CRYPT_OK) {
-         fprintf(stderr, "File hash error: %s\n", error_to_string(err));
+         fprintf(stderr, "%s: File hash error: %s\n", hashsum, error_to_string(err));
          return EXIT_FAILURE;
          return EXIT_FAILURE;
       } else {
       } else {
           for (x = 0; x < w; x++) {
           for (x = 0; x < w; x++) {
@@ -245,7 +245,7 @@ int main(int argc, char **argv)
       for (z = 3; z < argc; z++) {
       for (z = 3; z < argc; z++) {
          w = sizeof(hash_buffer);
          w = sizeof(hash_buffer);
          if ((err = hash_file(idx,argv[z],hash_buffer,&w)) != CRYPT_OK) {
          if ((err = hash_file(idx,argv[z],hash_buffer,&w)) != CRYPT_OK) {
-            fprintf(stderr, "File hash error: %s\n", error_to_string(err));
+            fprintf(stderr, "%s: File hash error: %s\n", hashsum, error_to_string(err));
             return EXIT_FAILURE;
             return EXIT_FAILURE;
          } else {
          } else {
              printf_hex(hash_buffer, w);
              printf_hex(hash_buffer, w);