Author: Adam <git@apiote.tk>
print errors to stderr
meowsum.c | 22 +++++++++++-----------
diff --git a/meowsum.c b/meowsum.c index 991c5153faa563fce472563047c046bd919bae60..20b12ef8329880ac886fd637423193969790e6ed 100644 --- a/meowsum.c +++ b/meowsum.c @@ -83,8 +83,8 @@ } else { fd = open(path, 0); } if (fd == -1) { - perror("error: "); - printf("error opening file %s\n", path); + perror("error"); + fprintf(stderr, "error opening file %s\n", path); return NULL; } @@ -92,8 +92,8 @@ *size = 0; hash = malloc(sizeof(meow_u128)); if (hash == NULL) { - perror("error: "); - printf("error mallocing hash for %s\n", path); + perror("error"); + fprintf(stderr, "error mallocing hash for %s\n", path); return NULL; } @@ -101,8 +101,8 @@ MeowBegin(&state, MeowDefaultSeed); while (true) { read_bytes = read(fd, buffer, 8192); if (read_bytes == -1) { - perror("error: "); - printf("error reading file %s\n", path); + perror("error"); + fprintf(stderr, "error reading file %s\n", path); close(fd); return NULL; } @@ -149,12 +149,12 @@ for (int i = start; i < argc; ++i) { hash = calculate_checksum(argv[i], &size); if (hash == NULL) { - printf("error while calculating %s\n", argv[i]); + fprintf(stderr, "error while calculating %s\n", argv[i]); return false; } hex_hash = format_sum(*hash, hash_size); if (hex_hash == NULL) { - printf("error while formating hex hash for %s\n", argv[i]); + fprintf(stderr, "error while formating hex hash for %s\n", argv[i]); free(hash); return false; } @@ -194,7 +194,7 @@ if (feof(file)) { break; } else { perror("error"); - printf("while reading line in %s\n", argv[i]); + fprintf(stderr, "while reading line in %s\n", argv[i]); return false; } } @@ -211,7 +211,7 @@ } else { // todo missing hash = calculate_checksum(path, &size); if (hash == NULL) { - printf("error while calculating %s\n", path); + fprintf(stderr, "error while calculating %s\n", path); free(hash); free(path); free(line); @@ -219,7 +219,7 @@ continue; } hex_hash = format_sum(*hash, hash_size); if (hex_hash == NULL) { - printf("error while formating hex hash for %s\n", path); + fprintf(stderr, "error while formating hex hash for %s\n", path); free(hex_hash); free(hash); free(path);