1 /*
2 * Copyright (c) 2002 Fabrice Bellard
3 * Copyright (c) 2013 Michael Niedermayer
4 * Copyright (c) 2013 James Almer
5 *
6 * This file is part of FFmpeg.
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #include "config.h"
27
28 #include <errno.h>
29 #include <fcntl.h>
30 #include <stdio.h>
31 #include <sys/stat.h>
32
33 #if HAVE_IO_H
34 #include <io.h>
35 #endif
36 #if HAVE_UNISTD_H
37 #include <unistd.h>
38 #endif
39
41
44
46 {
47 int i = 0;
49
50 printf("usage: ffhash [algorithm] [input]...\n");
51 printf("Supported hash algorithms:");
52 do {
54 if (name)
55 printf(" %s", name);
56 i++;
57 } while(name);
58 printf("\n");
59 }
60
62 {
64
67 for (i = 0; i <
len; i++)
68 printf(
"%02x",
res[i]);
69 }
70
72 {
74 int fd,
flags = O_RDONLY;
76
77 #ifdef O_BINARY
79 #endif
80 if (file) fd = open(file, flags);
81 else fd = 0;
82 if (fd == -1) {
84 ret = 1;
86 }
87
89 for (;;) {
90 ssize_t
size = read(fd, buffer,
SIZE);
91 if (size < 0) {
94 printf("+READ-FAILED: %s", strerror(errno));
95 ret = 2;
97 } else if(!size)
98 break;
100 }
102
105 if (file)
106 printf(" *%s", file);
107 printf("\n");
108
110 }
111
112 int main(
int argc,
char **argv)
113 {
114 int i;
116
117 if (argc == 1) {
119 return 0;
120 }
121
123 switch(ret) {
125 printf("Invalid hash type: %s\n", argv[1]);
126 break;
128 printf("%s\n", strerror(errno));
129 break;
130 }
131 return 1;
132 }
135 printf("%s\n", strerror(errno));
136 return 1;
137 }
138
139 for (i = 2; i < argc; i++)
140 ret |=
check(argv[i]);
141
142 if (argc < 3)
144
147
149 }