Merge Official Source

This commit is contained in:
CN_SZTL
2020-11-12 10:51:57 +08:00
74 changed files with 695 additions and 791 deletions

View File

@@ -85,6 +85,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/stat.h>
#define ARRAY_SIZE(_n) (sizeof(_n) / sizeof((_n)[0]))
@@ -736,7 +737,10 @@ static int usage(const char *progname)
{
int i;
fprintf(stderr, "Usage: %s <hash type> [<file>...]\n"
fprintf(stderr, "Usage: %s <hash type> [options] [<file>...]\n"
"Options:\n"
" -n Print filename(s)\n"
"\n"
"Supported hash types:", progname);
for (i = 0; i < ARRAY_SIZE(types); i++)
@@ -767,6 +771,13 @@ static int hash_file(struct hash_type *t, const char *filename, bool add_filenam
if (!filename || !strcmp(filename, "-")) {
str = t->func(stdin);
} else {
struct stat path_stat;
stat(filename, &path_stat);
if (S_ISDIR(path_stat.st_mode)) {
fprintf(stderr, "Failed to open '%s': Is a directory\n", filename);
return 1;
}
FILE *f = fopen(filename, "r");
if (!f) {
@@ -820,8 +831,11 @@ int main(int argc, char **argv)
if (argc < 2)
return hash_file(t, NULL, add_filename);
for (i = 0; i < argc - 1; i++)
hash_file(t, argv[1 + i], add_filename);
for (i = 0; i < argc - 1; i++) {
int ret = hash_file(t, argv[1 + i], add_filename);
if (ret)
return ret;
}
return 0;
}