Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports
Path: blob/main/misc/bdelta/files/patch-bpatch.cpp
18160 views
1
--- bpatch.cpp.orig 2013-01-30 20:16:01 UTC
2
+++ bpatch.cpp
3
@@ -7,6 +7,8 @@
4
#include "file.h"
5
#include "compatibility.h"
6
7
+#define FEFE
8
+
9
bool copy_bytes_to_file(FILE *infile, FILE *outfile, unsigned numleft) {
10
size_t numread;
11
do {
12
@@ -42,10 +44,17 @@ int main(int argc, char **argv) {
13
return 1;
14
}
15
unsigned short version = read_word(patchfile);
16
+#ifdef FEFE
17
+ if (version != 1 && version != 2) {
18
+ printf("unsupported patch version\n");
19
+ return 1;
20
+ }
21
+#else
22
if (version != 1) {
23
printf("unsupported patch version\n");
24
return 1;
25
}
26
+#endif
27
char intsize;
28
fread_fixed(patchfile, &intsize, 1);
29
if (intsize != 4) {
30
@@ -57,14 +66,32 @@ int main(int argc, char **argv) {
31
32
unsigned nummatches = read_dword(patchfile);
33
34
+#ifdef FEFE
35
+ long long * copyloc1 = new long long[nummatches + 1];
36
+ long long * copyloc2 = new long long[nummatches + 1];
37
+ unsigned * copynum = new unsigned[nummatches + 1];
38
+#else
39
unsigned * copyloc1 = new unsigned[nummatches + 1];
40
unsigned * copyloc2 = new unsigned[nummatches + 1];
41
unsigned * copynum = new unsigned[nummatches + 1];
42
+#endif
43
44
for (unsigned i = 0; i < nummatches; ++i) {
45
+#ifdef FEFE
46
+ if (version==2) {
47
+ copyloc1[i] = read_varint(patchfile);
48
+ copyloc2[i] = read_varint(patchfile);
49
+ copynum[i] = read_varint(patchfile);
50
+ } else {
51
copyloc1[i] = read_dword(patchfile);
52
copyloc2[i] = read_dword(patchfile);
53
copynum[i] = read_dword(patchfile);
54
+ }
55
+#else
56
+ copyloc1[i] = read_dword(patchfile);
57
+ copyloc2[i] = read_dword(patchfile);
58
+ copynum[i] = read_dword(patchfile);
59
+#endif
60
size2 -= copyloc2[i] + copynum[i];
61
}
62
if (size2) {
63
@@ -77,16 +104,22 @@ int main(int argc, char **argv) {
64
FILE *outfile = fopen(argv[2], "wb");
65
66
for (unsigned i = 0; i < nummatches; ++i) {
67
+// printf("%u/%u: copy %u bytes from patch file ofs %ld (dest ofs %u)\n",i,nummatches,copyloc2[i],ftell(patchfile),ftell(outfile));
68
if (!copy_bytes_to_file(patchfile, outfile, copyloc2[i])) {
69
printf("Error. patchfile is truncated\n");
70
return -1;
71
}
72
73
- int copyloc = copyloc1[i];
74
+ long long copyloc = copyloc1[i];
75
fseek(ref, copyloc, SEEK_CUR);
76
77
+ long curofs=ftell(ref);
78
+
79
+#ifdef FEFE
80
+// printf("%u/%u: (%d -> %u,%d -> %u,%u)\n",i,nummatches-1,copyloc,ftell(ref),copyloc2[i],ftell(outfile),copynum[i]);
81
+#endif
82
if (!copy_bytes_to_file(ref, outfile, copynum[i])) {
83
- printf("Error while copying from reference file\n");
84
+ printf("Error while copying from reference file (ofs %ld, %u bytes)\n", curofs, copynum[i]);
85
return -1;
86
}
87
}
88
89