From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 48F091382C5 for ; Sun, 17 May 2020 12:35:46 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 55A7FE0909; Sun, 17 May 2020 12:35:45 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 3025AE08FB for ; Sun, 17 May 2020 12:35:45 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 23F8534F8A0 for ; Sun, 17 May 2020 12:35:44 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 8BEC924E for ; Sun, 17 May 2020 12:35:42 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1589718772.2dce04019d38a49f7930db13e62dd47ecf5f9471.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: libq/hash.c libq/hash.h X-VCS-Directories: libq/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 2dce04019d38a49f7930db13e62dd47ecf5f9471 X-VCS-Branch: master Date: Sun, 17 May 2020 12:35:42 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 94365562-ffc4-47c4-9b88-bf9582255ee5 X-Archives-Hash: 9e9d253c19d844ad4073d88b5550f994 commit: 2dce04019d38a49f7930db13e62dd47ecf5f9471 Author: Fabian Groffen gentoo org> AuthorDate: Sun May 17 12:32:52 2020 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Sun May 17 12:32:52 2020 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=2dce0401 hash_multiple_file_fd: return success status Signed-off-by: Fabian Groffen gentoo.org> libq/hash.c | 29 ++++++++++++++++++----------- libq/hash.h | 4 ++-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/libq/hash.c b/libq/hash.c index a174a0c..a51ea6a 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 204da5f..f85080d 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);