summaryrefslogtreecommitdiff
path: root/ccan/crcsync/_info
blob: 9ebb8bd8a01e7e844ccc62e90bc0454d11904781 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "config.h"
#include <stdio.h>
#include <string.h>

/**
 * crcsync - routines to use crc for an rsync-like protocol.
 *
 * This is a complete library for synchronization using a variant of the
 * rsync protocol.
 *
 * Example:
 *	// Calculate checksums of file (3-arg mode)
 *	// Or print differences between file and checksums (4+ arg mode)
 *	#include <ccan/crcsync/crcsync.h>
 *	#include <ccan/tal/grab_file/grab_file.h>
 *	#include <ccan/tal/tal.h>
 *	#include <stdio.h>
 *	#include <stdlib.h>
 *	#include <err.h>
 *	
 *	static void print_result(long result)
 *	{
 *		if (result < 0)
 *			printf("MATCHED CRC %lu\n", -result - 1);
 *		else if (result > 0)
 *			printf("%lu literal bytes\n", result);
 *	}
 *	
 *	int main(int argc, char *argv[])
 *	{
 *		size_t len, used, blocksize;
 *		char *file;
 *		struct crc_context *ctx;
 *		uint64_t *crcs;
 *		long res, i;
 *	
 *		if (argc < 3 || (blocksize = atoi(argv[1])) == 0)
 *			errx(1, "Usage: %s <blocksize> <file> <crc>...\n"
 *			     "OR: %s <blocksize> <file>", argv[0], argv[0]);
 *	
 *		file = grab_file(NULL, argv[2]);
 *		if (!file)
 *			err(1, "Opening file %s", argv[2]);
 *		len = tal_count(file) - 1;
 *
 *		if (argc == 3) {
 *			// Short form prints CRCs of file for use in long form.
 *			used = (len + blocksize - 1) / blocksize;
 *			crcs = malloc(used * sizeof(crcs[0]));
 *			crc_of_blocks(file, len, blocksize, 32, crcs);
 *			for (i = 0; i < used; i++)
 *				printf("%llu ", (long long)crcs[i]);
 *			printf("\n");
 *			return 0;
 *		}
 *	
 *		crcs = malloc((argc - 3) * sizeof(uint32_t));
 *		for (i = 0; i < argc-3; i++)
 *			crcs[i] = atoi(argv[3+i]);
 *	
 *		ctx = crc_context_new(blocksize, 32, crcs, argc-3, 0);
 *		for (used = 0; used < len; ) {
 *			used += crc_read_block(ctx, &res, file+used, len-used);
 *			print_result(res);
 *		}
 *		while ((res = crc_read_flush(ctx)) != 0)
 *			print_result(res);
 *	
 *		return 0;
 *	}
 *
 * License: LGPL (v2.1 or any later version)
 * Author: Rusty Russell <rusty@rustcorp.com.au>
 * Ccanlint:
 *	// We actually depend on the GPL crc routines, so not really LGPL :(
 *	license_depends_compat FAIL
 */
int main(int argc, char *argv[])
{
	if (argc != 2)
		return 1;

	if (strcmp(argv[1], "depends") == 0) {
		printf("ccan/crc\n");
		return 0;
	}
	if (strcmp(argv[1], "testdepends") == 0) {
		printf("ccan/array_size\n");
		return 0;
	}

	return 1;
}