diff options
| author | Chloe M. <chloe@aptel.org> | 2026-08-22 06:48:01 +0000 |
|---|---|---|
| committer | Chloe M. <chloe@aptel.org> | 2026-08-22 09:45:33 +0000 |
| commit | 7683205c69c76b6515c242429a927974aedfb5c0 (patch) | |
| tree | 0d6661f646f7789681b99afab5f3eb2eb7ecb7e4 /core/hash.c | |
| parent | f0691430d86a727b4ffee0f6ea3b355baecd6414 (diff) | |
core: build: Add manifest handling
This resolves redundant rebuilds by detecting when there are differences
in a built file.
Signed-off-by: Chloe M. <chloe@aptel.org>
Diffstat (limited to 'core/hash.c')
| -rw-r--r-- | core/hash.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/core/hash.c b/core/hash.c new file mode 100644 index 0000000..557e406 --- /dev/null +++ b/core/hash.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2026, Chloe M., et al. + * Provided under the BSD-3 clause. + */ + +#include <sys/mman.h> +#include <stdio.h> +#include <unistd.h> +#include <fcntl.h> +#include "bop/hash.h" + +int +bop_hash_file(const char *path, char hashres[BOP_HASH_LEN]) +{ + int fd; + size_t len, i; + uint8_t hash[SHA256_DIGEST_LENGTH]; + void *mem; + + if (path == NULL) { + return -1; + } + + if ((fd = open(path, O_RDONLY)) < 0) { + perror("open"); + return -1; + } + + /* Grab the file length */ + len = lseek(fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + + /* Map the file */ + mem = mmap( + NULL, + len, + PROT_READ, + MAP_SHARED, + fd, + 0 + ); + + if (mem == NULL) { + perror("mmap"); + close(fd); + return -1; + } + + SHA256(mem, len, hash); + for (i = 0; i < SHA256_DIGEST_LENGTH; ++i) { + sprintf((char *)hashres + i*2, "%02X", hash[i]); + } + return 0; +} |
