mirror of
https://github.com/void-linux/void-packages.git
synced 2025-07-27 16:02:55 +02:00
xbps-digest: accept any number of arbitrary files in argv.
--HG-- extra : convert_revision : 42a96b8435a2508a06b48f327f25dc97e16db233
This commit is contained in:
parent
5803db23a3
commit
de67397983
1 changed files with 24 additions and 21 deletions
|
@ -39,6 +39,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
|
||||||
typedef uint8_t sha2_byte; /* Exactly 1 byte */
|
typedef uint8_t sha2_byte; /* Exactly 1 byte */
|
||||||
typedef uint32_t sha2_word32; /* Exactly 4 bytes */
|
typedef uint32_t sha2_word32; /* Exactly 4 bytes */
|
||||||
|
@ -414,7 +415,7 @@ SHA256_End(SHA256_CTX *ctx, uint8_t *buffer)
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: xbps-digest <file>\n");
|
fprintf(stderr, "usage: xbps-digest <file> <file1+N> ...\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,30 +425,32 @@ main(int argc, char **argv)
|
||||||
SHA256_CTX ctx;
|
SHA256_CTX ctx;
|
||||||
uint8_t buffer[BUFSIZ * 20], *digest;
|
uint8_t buffer[BUFSIZ * 20], *digest;
|
||||||
ssize_t bytes;
|
ssize_t bytes;
|
||||||
int fd;
|
int i, fd;
|
||||||
|
|
||||||
if (argc != 2)
|
if (argc < 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
if ((fd = open(argv[1], O_RDONLY)) == -1) {
|
for (i = 1; i < argc; i++) {
|
||||||
printf("xbps-digest: cannot open %s (%s)\n", argv[1],
|
if ((fd = open(argv[i], O_RDONLY)) == -1) {
|
||||||
strerror(errno));
|
printf("xbps-digest: cannot open %s (%s)\n", argv[i],
|
||||||
exit(1);
|
strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
digest = malloc(SHA256_DIGEST_LENGTH * 2 + 1);
|
||||||
|
if (digest == NULL) {
|
||||||
|
printf("xbps-digest: malloc failed (%s)\n", strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHA256_Init(&ctx);
|
||||||
|
while ((bytes = read(fd, buffer, sizeof(buffer))) > 0)
|
||||||
|
SHA256_Update(&ctx, buffer, (size_t)bytes);
|
||||||
|
|
||||||
|
printf("%s\n", SHA256_End(&ctx, digest));
|
||||||
|
free(digest);
|
||||||
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
digest = malloc(SHA256_DIGEST_LENGTH * 2 + 1);
|
|
||||||
if (digest == NULL) {
|
|
||||||
printf("xbps-digest: malloc failed (%s)\n", strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
SHA256_Init(&ctx);
|
|
||||||
while ((bytes = read(fd, buffer, sizeof(buffer))) > 0)
|
|
||||||
SHA256_Update(&ctx, buffer, (size_t)bytes);
|
|
||||||
|
|
||||||
printf("%s\n", SHA256_End(&ctx, digest));
|
|
||||||
free(digest);
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue