Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 79 lines (69 sloc) 1.801 kb
a310d43 [PATCH] Deltification library work by Nicolas Pitre.
Nicolas Pitre authored
1 /*
2 * test-delta.c: test code to exercise diff-delta.c and patch-delta.c
3 *
03aa8ff @npitre Nicolas Pitre has a new email address
npitre authored
4 * (C) 2005 Nicolas Pitre <nico@fluxnic.net>
a310d43 [PATCH] Deltification library work by Nicolas Pitre.
Nicolas Pitre authored
5 *
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.
9 */
10
8502357 simplify inclusion of system header files.
Junio C Hamano authored
11 #include "git-compat-util.h"
a310d43 [PATCH] Deltification library work by Nicolas Pitre.
Nicolas Pitre authored
12 #include "delta.h"
adb7b5f Fix compilation of test-delta
Martin Koegler authored
13 #include "cache.h"
a310d43 [PATCH] Deltification library work by Nicolas Pitre.
Nicolas Pitre authored
14
adb7b5f Fix compilation of test-delta
Martin Koegler authored
15 static const char usage_str[] =
a310d43 [PATCH] Deltification library work by Nicolas Pitre.
Nicolas Pitre authored
16 "test-delta (-d|-p) <from_file> <data_file> <out_file>";
17
18 int main(int argc, char *argv[])
19 {
20 int fd;
21 struct stat st;
22 void *from_buf, *data_buf, *out_buf;
23 unsigned long from_size, data_size, out_size;
24
25 if (argc != 5 || (strcmp(argv[1], "-d") && strcmp(argv[1], "-p"))) {
b978403 @davvid tests: use a lowercase "usage:" string
davvid authored
26 fprintf(stderr, "usage: %s\n", usage_str);
a310d43 [PATCH] Deltification library work by Nicolas Pitre.
Nicolas Pitre authored
27 return 1;
28 }
29
30 fd = open(argv[2], O_RDONLY);
31 if (fd < 0 || fstat(fd, &st)) {
32 perror(argv[2]);
33 return 1;
34 }
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) {
38 perror(argv[2]);
e35f982 @proski [PATCH] mmap error handling
proski authored
39 close(fd);
a310d43 [PATCH] Deltification library work by Nicolas Pitre.
Nicolas Pitre authored
40 return 1;
41 }
42 close(fd);
43
44 fd = open(argv[3], O_RDONLY);
45 if (fd < 0 || fstat(fd, &st)) {
46 perror(argv[3]);
47 return 1;
48 }
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) {
52 perror(argv[3]);
e35f982 @proski [PATCH] mmap error handling
proski authored
53 close(fd);
a310d43 [PATCH] Deltification library work by Nicolas Pitre.
Nicolas Pitre authored
54 return 1;
55 }
56 close(fd);
57
58 if (argv[1][1] == 'd')
59 out_buf = diff_delta(from_buf, from_size,
75c42d8 Add a "max_size" parameter to diff_delta()
Linus Torvalds authored
60 data_buf, data_size,
3c84974 [PATCH] Fixlets on top of Nico's clean-up.
Junio C Hamano authored
61 &out_size, 0);
a310d43 [PATCH] Deltification library work by Nicolas Pitre.
Nicolas Pitre authored
62 else
63 out_buf = patch_delta(from_buf, from_size,
75c42d8 Add a "max_size" parameter to diff_delta()
Linus Torvalds authored
64 data_buf, data_size,
65 &out_size);
a310d43 [PATCH] Deltification library work by Nicolas Pitre.
Nicolas Pitre authored
66 if (!out_buf) {
67 fprintf(stderr, "delta operation failed (returned NULL)\n");
68 return 1;
69 }
70
71 fd = open (argv[4], O_WRONLY|O_CREAT|O_TRUNC, 0666);
93822c2 @awhitcroft short i/o: fix calls to write to use xwrite or write_in_full
awhitcroft authored
72 if (fd < 0 || write_in_full(fd, out_buf, out_size) != out_size) {
a310d43 [PATCH] Deltification library work by Nicolas Pitre.
Nicolas Pitre authored
73 perror(argv[4]);
74 return 1;
75 }
76
77 return 0;
78 }
Something went wrong with that request. Please try again.