-
Notifications
You must be signed in to change notification settings - Fork 67
/
verify.c
68 lines (61 loc) · 1.25 KB
/
verify.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdlib.h>
#include "snappy.h"
#include "map.h"
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include "util.h"
int main(int ac, char **av)
{
int failed = 0, verbose = 0;
struct snappy_env env;
snappy_init_env(&env);
if (av[1] && !strcmp(av[1], "-v")) {
verbose++;
av++;
}
while (*++av) {
size_t size;
char *map = mapfile(*av, O_RDONLY, &size);
if (!map) {
if (size > 0) {
perror(*av);
failed = 1;
}
continue;
}
size_t outlen;
int err;
char *out = xmalloc(snappy_max_compressed_length(size));
char *buf2 = xmalloc(size);
err = snappy_compress(&env, map, size, out, &outlen);
if (err) {
failed = 1;
printf("compression of %s failed: %d\n", *av, err);
goto next;
}
err = snappy_uncompress(out, outlen, buf2);
if (err) {
failed = 1;
printf("uncompression of %s failed: %d\n", *av, err);
goto next;
}
if (memcmp(buf2, map, size)) {
int o = compare(buf2, map, size);
if (o >= 0) {
failed = 1;
printf("final comparision of %s failed at %d of %lu\n",
*av, o, (unsigned long)size);
}
} else {
if (verbose)
printf("%s OK!\n", *av);
}
next:
unmap_file(map, size);
free(out);
free(buf2);
}
return failed;
}