2 * Copyright (c) 2002 Fabrice Bellard
3 * Copyright (c) 2013 Michael Niedermayer
4 * Copyright (c) 2013 James Almer
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "libavutil/error.h"
25 #include "libavutil/hash.h"
26 #include "libavutil/mem.h"
42 static struct AVHashContext *hash;
45 static void usage(void)
50 printf("usage: ffhash [algorithm] [input]...\n");
51 printf("Supported hash algorithms:");
53 name = av_hash_names(i);
61 static void finish(void)
63 int i, len = av_hash_get_size(hash);
65 printf("%s=0x", av_hash_get_name(hash));
66 av_hash_final(hash, res);
67 for (i = 0; i < len; i++)
68 printf("%02x", res[i]);
71 static int check(char *file)
74 int fd, flags = O_RDONLY;
80 if (file) fd = open(file, flags);
83 printf("%s=OPEN-FAILED: %s:", av_hash_get_name(hash), strerror(errno));
90 int size = read(fd, buffer, SIZE);
94 printf("+READ-FAILED: %s", strerror(errno));
99 av_hash_update(hash, buffer, size);
106 printf(" *%s", file);
112 int main(int argc, char **argv)
122 if ((ret = av_hash_alloc(&hash, argv[1])) < 0) {
124 case AVERROR(EINVAL):
125 printf("Invalid hash type: %s\n", argv[1]);
127 case AVERROR(ENOMEM):
128 printf("%s\n", strerror(errno));
133 res = av_malloc(av_hash_get_size(hash));
135 printf("%s\n", strerror(errno));
139 for (i = 2; i < argc; i++)
140 ret |= check(argv[i]);
145 av_hash_freep(&hash);