6 * crcsync - routines to use crc for an rsync-like protocol.
8 * This is a complete library for synchronization using a variant of the
12 * // Calculate checksums of file (3-arg mode)
13 * // Or print differences between file and checksums (4+ arg mode)
14 * #include <ccan/crcsync/crcsync.h>
15 * #include <ccan/grab_file/grab_file.h>
20 * static void print_result(long result)
23 * printf("MATCHED CRC %lu\n", -result - 1);
24 * else if (result > 0)
25 * printf("%lu literal bytes\n", result);
28 * int main(int argc, char *argv[])
30 * size_t len, used, blocksize;
32 * struct crc_context *ctx;
36 * if (argc < 3 || (blocksize = atoi(argv[1])) == 0)
37 * errx(1, "Usage: %s <blocksize> <file> <crc>...\n"
38 * "OR: %s <blocksize> <file>", argv[0], argv[0]);
40 * file = grab_file(NULL, argv[2], &len);
42 * err(1, "Opening file %s", argv[2]);
45 * // Short form prints CRCs of file for use in long form.
46 * used = (len + blocksize - 1) / blocksize;
47 * crcs = malloc(used * sizeof(uint32_t));
48 * crc_of_blocks(file, len, blocksize, 32, crcs);
49 * for (i = 0; i < used; i++)
50 * printf("%i ", crcs[i]);
55 * crcs = malloc((argc - 3) * sizeof(uint32_t));
56 * for (i = 0; i < argc-3; i++)
57 * crcs[i] = atoi(argv[3+i]);
59 * ctx = crc_context_new(blocksize, 32, crcs, argc-3);
60 * for (used = 0; used < len; ) {
61 * used += crc_read_block(ctx, &res, file+used, len-used);
64 * while ((res = crc_read_flush(ctx)) != 0)
70 * Licence: LGPL (v2 or any later version)
72 int main(int argc, char *argv[])
77 if (strcmp(argv[1], "depends") == 0) {
79 printf("ccan/array_size\n");