This example is a simple command line application that takes one or more arguments. It demonstrates a typical use of the hashing API with allocation, initialization, updating, and finalizing.
#include "config.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#if HAVE_IO_H
#include <io.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#define SIZE 65536
{
int i = 0;
printf("usage: ffhash [b64:]algorithm [input]...\n");
printf("Supported hash algorithms:");
do {
if (name)
printf(" %s", name);
i++;
} while(name);
printf("\n");
}
{
printf("b64:%s", res);
} else {
printf("0x%s", res);
}
}
static int check(
char *file)
{
int fd,
flags = O_RDONLY;
int ret = 0;
#ifdef O_BINARY
#endif
if (file) fd = open(file, flags);
else fd = 0;
if (fd == -1) {
ret = 1;
}
for (;;) {
if (size < 0) {
int err = errno;
close(fd);
printf("+READ-FAILED: %s", strerror(err));
ret = 2;
} else if(!size)
break;
}
close(fd);
if (file)
printf(" *%s", file);
printf("\n");
return ret;
}
int main(
int argc,
char **argv)
{
int i;
int ret = 0;
const char *hash_name;
if (argc == 1) {
return 0;
}
hash_name = argv[1];
switch(ret) {
printf("Invalid hash type: %s\n", hash_name);
break;
printf("%s\n", strerror(errno));
break;
}
return 1;
}
for (i = 2; i < argc; i++)
if (argc < 3)
return ret;
}