diff options
author | Fabian Groffen <grobian@gentoo.org> | 2020-05-17 14:32:52 +0200 |
---|---|---|
committer | Fabian Groffen <grobian@gentoo.org> | 2020-05-17 14:32:52 +0200 |
commit | 2dce04019d38a49f7930db13e62dd47ecf5f9471 (patch) | |
tree | e3f857c3bf2a85a3947fc2e67a68b5a9fab29afd | |
parent | qtbz2: drop warning about archive not being bz2 compressed (diff) | |
download | portage-utils-2dce04019d38a49f7930db13e62dd47ecf5f9471.tar.gz portage-utils-2dce04019d38a49f7930db13e62dd47ecf5f9471.tar.bz2 portage-utils-2dce04019d38a49f7930db13e62dd47ecf5f9471.zip |
hash_multiple_file_fd: return success status
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
-rw-r--r-- | libq/hash.c | 29 | ||||
-rw-r--r-- | libq/hash.h | 4 |
2 files changed, 20 insertions, 13 deletions
diff --git a/libq/hash.c b/libq/hash.c index a174a0cd..a51ea6ad 100644 --- a/libq/hash.c +++ b/libq/hash.c @@ -113,7 +113,7 @@ hash_hex(char *out, const unsigned char *buf, const int length) * left untouched, e.g. they can be NULL. The number of bytes read from * the file pointed to by fname is returned in the flen argument. */ -void +int hash_multiple_file_fd( int fd, char *md5, @@ -148,7 +148,7 @@ hash_multiple_file_fd( #endif if ((f = fdopen(fd, "r")) == NULL) - return; + return -1; #ifdef HAVE_SSL MD5_Init(&m5); @@ -164,6 +164,7 @@ hash_multiple_file_fd( blake2b_init(&bl2b, BLAKE2B_OUTBYTES); #endif + *flen = 0; while ((len = fread(data, 1, sizeof(data), f)) > 0) { *flen += len; #pragma omp parallel sections @@ -291,9 +292,10 @@ hash_multiple_file_fd( } fclose(f); + return 0; } -void +int hash_multiple_file_at_cb( int pfd, const char *fname, @@ -307,19 +309,23 @@ hash_multiple_file_at_cb( size_t *flen, int hashes) { + int ret; int fd = openat(pfd, fname, O_RDONLY | O_CLOEXEC); - if (fd == -1) { - *flen = 0; - return; - } - if (cb != NULL) + if (fd == -1) + return -1; + + if (cb != NULL) { fd = cb(fd, fname); + if (fd == -1) + return -1; + } - hash_multiple_file_fd(fd, md5, sha1, sha256, sha512, + ret = hash_multiple_file_fd(fd, md5, sha1, sha256, sha512, whrlpl, blak2b, flen, hashes); close(fd); + return ret; } static char _hash_file_buf[128 + 1]; @@ -335,10 +341,11 @@ hash_file_at_cb(int pfd, const char *fname, int hash, hash_cb_t cb) case HASH_SHA512: case HASH_WHIRLPOOL: case HASH_BLAKE2B: - hash_multiple_file_at_cb(pfd, fname, cb, + if (hash_multiple_file_at_cb(pfd, fname, cb, _hash_file_buf, _hash_file_buf, _hash_file_buf, _hash_file_buf, _hash_file_buf, _hash_file_buf, - &dummy, hash); + &dummy, hash) != 0) + return NULL; break; default: return NULL; diff --git a/libq/hash.h b/libq/hash.h index 204da5f8..f85080df 100644 --- a/libq/hash.h +++ b/libq/hash.h @@ -30,10 +30,10 @@ enum hash_impls { typedef int (*hash_cb_t) (int, const char *); void hash_hex(char *out, const unsigned char *buf, const int length); -void hash_multiple_file_fd( +int hash_multiple_file_fd( int fd, char *md5, char *sha1, char *sha256, char *sha512, char *whrlpl, char *blak2b, size_t *flen, int hashes); -void hash_multiple_file_at_cb( +int hash_multiple_file_at_cb( int pfd, const char *fname, hash_cb_t cb, char *md5, char *sha1, char *sha256, char *sha512, char *whrlpl, char *blak2b, size_t *flen, int hashes); |