#include <stdio.h>
#include <errno.h>
struct timespec start;
};
static void
{
struct timespec elapsed;
const char *s_unit, *r_unit;
size = amount;
if (size >= 1.0e9) {
s_unit = "Gb";
size /= 1.0e9;
} else if (size > 1.0e6) {
s_unit = "Mb";
size /= 1.0e6;
} else if (size > 1.0e3) {
s_unit = "Kb";
size /= 1.0e3;
} else {
s_unit = "b";
}
if (rate >= 1.0e9) {
r_unit = "Gb";
rate /= 1.0e9;
} else if (rate > 1.0e6) {
r_unit = "Mb";
rate /= 1.0e6;
} else if (rate > 1.0e3) {
r_unit = "Kb";
rate /= 1.0e3;
} else {
r_unit = "b";
}
printf("%s chunk{#%" PRIu32 ", %zdb] %0.1f%s done in %0.3fseconds: %0.1f%s/s\n",
prefix, ctx->
idx, ctx->
chunk_size, size, s_unit, seconds, rate, r_unit);
}
static void
{
}
static void
{
int r;
if (r == 0) {
printf(
"%s\t%s\n", (
char *)buf.data, ctx->
file);
}
free(ctx);
}
static void
{
size_t chunk_size = -1;
if (argc < 2) {
fprintf(stderr,
"Usage:\n\t%s [-a <algorithm>] [-c chunk_size] [-k key] <file1> .. <fileN>\n", argv[0]);
return;
}
for (i = 1; i < argc; i++) {
};
int r;
if (argv[i][0] == '-') {
if (argv[i][1] == 'a') {
if (i + 1 < argc) {
algorithm = argv[i + 1];
i++;
continue;
} else
fputs("ERROR: argument -a missing value.\n", stderr);
} else if (argv[i][1] == 'k') {
if (i + 1 < argc) {
key = argv[i + 1];
i++;
continue;
} else
fputs("ERROR: argument -a missing value.\n", stderr);
} else if (argv[i][1] == 'c') {
if (i + 1 < argc) {
chunk_size = atoi(argv[i + 1]);
i++;
continue;
} else
fputs("ERROR: argument -c missing value.\n", stderr);
} else
fprintf(stderr, "ERROR: unknown option %s\n", argv[i]);
return;
}
if (!fr) {
fprintf(stderr, "ERROR: could not open file '%s': %s\n",
continue;
}
if (!blob) {
fprintf(stderr, "ERROR: could not create blob for file '%s'\n",
argv[i]);
continue;
}
if (!ctx) {
fprintf(stderr, "ERROR: could not allocate context memory "
"to process file '%s'\n", argv[i]);
continue;
}
if (key)
if (!mdh) {
fprintf(stderr, "ERROR: could not create message digest for "
" algorithm \"%s\": %s\n",
free(ctx);
continue;
}
if (chunk_size <= 0) {
if (r < 0) {
fprintf(stderr, "ERROR: could not feed message for "
" algorithm \"%s\": %s\n",
free(ctx);
continue;
}
} else {
size_t offset = 0;
while (offset < blob->size) {
size_t remaining = blob->
size - offset;
size_t clen = remaining > chunk_size ? chunk_size : remaining;
uint8_t *cmem = (uint8_t *)blob->
mem + offset;
bool is_last = offset + clen == blob->
size;
blob, cmem, clen);
if (!chunk) {
fprintf(stderr, "ERROR: could not create chunk blob at "
"mem %p, size=%zd\n", cmem, clen);
free(ctx);
continue;
}
if (r < 0) {
fprintf(stderr, "ERROR: could not feed chunk for "
" algorithm \"%s\": %s\n",
free(ctx);
continue;
}
offset += clen;
}
}
}
}
static void
{
}