]> git.ozlabs.org Git - ccan/blob - ccan/crcsync/_info
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / crcsync / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * crcsync - routines to use crc for an rsync-like protocol.
7  *
8  * This is a complete library for synchronization using a variant of the
9  * rsync protocol.
10  *
11  * Example:
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>
17  *      #include <stdio.h>
18  *      #include <stdlib.h>
19  *      #include <err.h>
20  *      
21  *      static void print_result(long result)
22  *      {
23  *              if (result < 0)
24  *                      printf("MATCHED CRC %lu\n", -result - 1);
25  *              else if (result > 0)
26  *                      printf("%lu literal bytes\n", result);
27  *      }
28  *      
29  *      int main(int argc, char *argv[])
30  *      {
31  *              size_t len, used, blocksize;
32  *              char *file;
33  *              struct crc_context *ctx;
34  *              uint64_t *crcs;
35  *              long res, i;
36  *      
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]);
40  *      
41  *              file = grab_file(NULL, argv[2]);
42  *              if (!file)
43  *                      err(1, "Opening file %s", argv[2]);
44  *              len = tal_count(file) - 1;
45  *
46  *              if (argc == 3) {
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]);
53  *                      printf("\n");
54  *                      return 0;
55  *              }
56  *      
57  *              crcs = malloc((argc - 3) * sizeof(uint32_t));
58  *              for (i = 0; i < argc-3; i++)
59  *                      crcs[i] = atoi(argv[3+i]);
60  *      
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);
64  *                      print_result(res);
65  *              }
66  *              while ((res = crc_read_flush(ctx)) != 0)
67  *                      print_result(res);
68  *      
69  *              return 0;
70  *      }
71  *
72  * License: LGPL (v2.1 or any later version)
73  * Author: Rusty Russell <rusty@rustcorp.com.au>
74  */
75 int main(int argc, char *argv[])
76 {
77         if (argc != 2)
78                 return 1;
79
80         if (strcmp(argv[1], "depends") == 0) {
81                 printf("ccan/crc\n");
82                 return 0;
83         }
84         if (strcmp(argv[1], "testdepends") == 0) {
85                 printf("ccan/array_size\n");
86                 return 0;
87         }
88         if (strcmp(argv[1], "ccanlint") == 0) {
89                 /* We actually depend on the GPL crc routines, so not really LGPL :( */
90                 printf("license_depends_compat FAIL\n");
91                 return 0;
92         }
93
94         return 1;
95 }