_info 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "config.h"
  4. /**
  5. * crcsync - routines to use crc for an rsync-like protocol.
  6. *
  7. * This is a complete library for synchronization using a variant of the
  8. * rsync protocol.
  9. *
  10. * Example:
  11. * // Calculate checksums of file (3-arg mode)
  12. * // Or print differences between file and checksums (4+ arg mode)
  13. * #include <ccan/crcsync/crcsync.h>
  14. * #include <ccan/grab_file/grab_file.h>
  15. * #include <stdio.h>
  16. * #include <stdlib.h>
  17. * #include <err.h>
  18. *
  19. * static void print_result(long result)
  20. * {
  21. * if (result < 0)
  22. * printf("MATCHED CRC %lu\n", -result - 1);
  23. * else if (result > 0)
  24. * printf("%lu literal bytes\n", result);
  25. * }
  26. *
  27. * int main(int argc, char *argv[])
  28. * {
  29. * size_t len, used, blocksize;
  30. * char *file;
  31. * struct crc_context *ctx;
  32. * uint32_t *crcs;
  33. * long res, i;
  34. *
  35. * if (argc < 3 || (blocksize = atoi(argv[1])) == 0)
  36. * errx(1, "Usage: %s <blocksize> <file> <crc>...\n"
  37. * "OR: %s <blocksize> <file>", argv[0], argv[0]);
  38. *
  39. * file = grab_file(NULL, argv[2], &len);
  40. * if (!file)
  41. * err(1, "Opening file %s", argv[2]);
  42. *
  43. * if (argc == 3) {
  44. * // Short form prints CRCs of file for use in long form.
  45. * used = (len + blocksize - 1) / blocksize;
  46. * crcs = malloc(used * sizeof(uint32_t));
  47. * crc_of_blocks(file, len, blocksize, 32, crcs);
  48. * for (i = 0; i < used; i++)
  49. * printf("%i ", crcs[i]);
  50. * printf("\n");
  51. * return 0;
  52. * }
  53. *
  54. * crcs = malloc((argc - 3) * sizeof(uint32_t));
  55. * for (i = 0; i < argc-3; i++)
  56. * crcs[i] = atoi(argv[3+i]);
  57. *
  58. * ctx = crc_context_new(blocksize, 32, crcs, argc-3);
  59. * for (used = 0; used < len; ) {
  60. * used += crc_read_block(ctx, &res, file+used, len-used);
  61. * print_result(res);
  62. * }
  63. * while ((res = crc_read_flush(ctx)) != 0)
  64. * print_result(res);
  65. *
  66. * return 0;
  67. * }
  68. *
  69. * Licence: LGPL (v2 or any later version)
  70. * Author: Rusty Russell <rusty@rustcorp.com.au>
  71. */
  72. int main(int argc, char *argv[])
  73. {
  74. if (argc != 2)
  75. return 1;
  76. if (strcmp(argv[1], "depends") == 0) {
  77. printf("ccan/crc\n");
  78. printf("ccan/array_size\n");
  79. return 0;
  80. }
  81. return 1;
  82. }