Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add sha256_fileat function
Baptiste Daroussin committed 11 years ago
commit 3d8bb23ed5306add5ea036e404513f0cc225b63e
parent e0f5caf
2 files changed +20 -1
modified libpkg/private/utils.h
@@ -96,6 +96,7 @@ int is_conf_file(const char *path, char *newpath, size_t len);
void sha256_buf(const char *, size_t len, char[SHA256_DIGEST_LENGTH * 2 +1]);
void sha256_buf_bin(const char *, size_t len, char[SHA256_DIGEST_LENGTH]);
int sha256_file(const char *, char[SHA256_DIGEST_LENGTH * 2 +1]);
+
int sha256_fileat(int fd, const char *, char[SHA256_DIGEST_LENGTH * 2 +1]);
int sha256_fd(int fd, char[SHA256_DIGEST_LENGTH * 2 +1]);
int md5_file(const char *, char[MD5_DIGEST_LENGTH * 2 +1]);

modified libpkg/utils.c
@@ -356,13 +356,31 @@ sha256_hash(unsigned char hash[SHA256_DIGEST_LENGTH],
}

int
+
sha256_fileat(int rootfd, const char *path,
+
    char out[SHA256_DIGEST_LENGTH * 2 + 1])
+
{
+
	int fd, ret;
+

+
	if ((fd = openat(rootfd, path, O_RDONLY)) == -1) {
+
		pkg_emit_errno("openat", path);
+
		return (EPKG_FATAL);
+
	}
+

+
	ret = sha256_fd(fd, out);
+

+
	close(fd);
+

+
	return (ret);
+
}
+

+
int
sha256_file(const char *path, char out[SHA256_DIGEST_LENGTH * 2 + 1])
{
	int fd;
	int ret;

	if ((fd = open(path, O_RDONLY)) == -1) {
-
		pkg_emit_errno("fopen", path);
+
		pkg_emit_errno("open", path);
		return (EPKG_FATAL);
	}