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/tal/grab_file/grab_file.h>
16 * #include <ccan/tal/tal.h>
21 * static void print_result(long result)
24 * printf("MATCHED CRC %lu\n", -result - 1);
25 * else if (result > 0)
26 * printf("%lu literal bytes\n", result);
29 * int main(int argc, char *argv[])
31 * size_t len, used, blocksize;
33 * struct crc_context *ctx;
37 * if (argc < 3 || (blocksize = atoi(argv[1])) == 0)
38 * errx(1, "Usage: %s <blocksize> <file> <crc>...\n"
39 * "OR: %s <blocksize> <file>", argv[0], argv[0]);
41 * file = grab_file(NULL, argv[2]);
43 * err(1, "Opening file %s", argv[2]);
44 * len = tal_count(file) - 1;
47 * // Short form prints CRCs of file for use in long form.
48 * used = (len + blocksize - 1) / blocksize;
49 * crcs = malloc(used * sizeof(crcs[0]));
50 * crc_of_blocks(file, len, blocksize, 32, crcs);
51 * for (i = 0; i < used; i++)
52 * printf("%llu ", (long long)crcs[i]);
57 * crcs = malloc((argc - 3) * sizeof(uint32_t));
58 * for (i = 0; i < argc-3; i++)
59 * crcs[i] = atoi(argv[3+i]);
61 * ctx = crc_context_new(blocksize, 32, crcs, argc-3, 0);
62 * for (used = 0; used < len; ) {
63 * used += crc_read_block(ctx, &res, file+used, len-used);
66 * while ((res = crc_read_flush(ctx)) != 0)
72 * License: LGPL (v2.1 or any later version)
73 * Author: Rusty Russell <rusty@rustcorp.com.au>
75 * // We actually depend on the GPL crc routines, so not really LGPL :(
76 * license_depends_compat FAIL
78 int main(int argc, char *argv[])
83 if (strcmp(argv[1], "depends") == 0) {
87 if (strcmp(argv[1], "testdepends") == 0) {
88 printf("ccan/array_size\n");