bsdiff-portable

A more portable version of Colin Percival's bsdiff
git clone git://git.sgregoratto.me/bsdiff-portable
Log | Files | Refs | README | LICENSE

commit 1c7657ae475ed3188876fd101ccb04195697efef
parent 70436d229d0fe1b6bc62fb5b254449e92b9da29d
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date:   Fri, 25 Sep 2020 13:55:17 +1000

fully document the file structure in bsdiff.c

The same information was copied twice in both programs. Now all the
info is in one neat comment.

While we're here, fix another comment to be KNF.

Diffstat:
Mbsdiff.c | 33++++++++++++++++++++++-----------
Mbspatch.c | 14--------------
2 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/bsdiff.c b/bsdiff.c @@ -130,16 +130,26 @@ main(int argc, char **argv) err(1, "reallocarray"); filelen = 0; - /* Header is - 0 8 "BSDIFF40" - 8 8 length of bzip2ed ctrl block - 16 8 length of bzip2ed diff block - 24 8 length of new file */ - /* File is - 0 32 Header - 32 ?? Bzip2ed ctrl block - ?? ?? Bzip2ed diff block - ?? ?? Bzip2ed extra block */ + /* + * The structure of a bsdiff patch is a 32 byte plaintext header + * and three bzip2'd data blocks. In more detail: + * + * offset size + * 0 8 "BSDIFF40" + * 8 8 sizeof(bzip2(ctrl block)): X + * 16 8 sizeof(bzip2(diff block)): Y + * 24 8 sizeof(newfile) + * 32 X bzip2(ctrl block) + * 32 + X Y bzip2(diff block) + * 32 + X + Y ?? bzip2(extra block) + * + * The ctrl block is a set of triples (x, y, z) that tells the patch + * program to: + * + * - Add x bytes from oldfile to x bytes from the diff block. + * - Copy y bytes from the extra block. + * - Seek forwards in oldfile by z bytes. + */ header.new_file_len = newsize; if (fwrite(&header, 1, sizeof(header), pf) != 32) err(1, "fwrite(%s, %zu)", argv[3], sizeof(header)); @@ -154,7 +164,8 @@ main(int argc, char **argv) * If we come across a large block of data that only differs by * less than 8 bytes, this loop takes a long time to go past it. * Track the number of times we're stuck in the block and break - * out of it. */ + * out of it. + */ int num_less_than_eight = 0; off_t prev_len, prev_oldscore, prev_pos; for (scsc = scan += len; scan < newsize; scan++) { diff --git a/bspatch.c b/bspatch.c @@ -106,20 +106,6 @@ main(int argc, char **argv) err(1, "pledge"); #endif - /* - File format: - 0 8 "BSDIFF40" - 8 8 X - 16 8 Y - 24 8 sizeof(newfile) - 32 X bzip2(control block) - 32+X Y bzip2(diff block) - 32+X+Y ??? bzip2(extra block) - with control block a set of triples (x,y,z) meaning "add x bytes - from oldfile to x bytes from the diff block; copy y bytes from the - extra block; seek forwards in oldfile by z bytes". - */ - /* Read header */ if (fread(header, 1, 32, f) != 32) { if (feof(f))