2 * test-delta.c: test code to exercise diff-delta.c and patch-delta.c
4 * (C) 2005 Nicolas Pitre <nico@fluxnic.net>
6 * This code is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include "git-compat-util.h"
15 static const char usage_str[] =
16 "test-delta (-d|-p) <from_file> <data_file> <out_file>";
18 int cmd_main(int argc, const char **argv)
22 void *from_buf, *data_buf, *out_buf;
23 unsigned long from_size, data_size, out_size;
25 if (argc != 5 || (strcmp(argv[1], "-d") && strcmp(argv[1], "-p"))) {
26 fprintf(stderr, "usage: %s\n", usage_str);
30 fd = open(argv[2], O_RDONLY);
31 if (fd < 0 || fstat(fd, &st)) {
35 from_size = st.st_size;
36 from_buf = mmap(NULL, from_size, PROT_READ, MAP_PRIVATE, fd, 0);
37 if (from_buf == MAP_FAILED) {
44 fd = open(argv[3], O_RDONLY);
45 if (fd < 0 || fstat(fd, &st)) {
49 data_size = st.st_size;
50 data_buf = mmap(NULL, data_size, PROT_READ, MAP_PRIVATE, fd, 0);
51 if (data_buf == MAP_FAILED) {
58 if (argv[1][1] == 'd')
59 out_buf = diff_delta(from_buf, from_size,
63 out_buf = patch_delta(from_buf, from_size,
67 fprintf(stderr, "delta operation failed (returned NULL)\n");
71 fd = open (argv[4], O_WRONLY|O_CREAT|O_TRUNC, 0666);
72 if (fd < 0 || write_in_full(fd, out_buf, out_size) != out_size) {