From 8fdedb9ac59bfe2026dd3b6f547993b279b643d5 Mon Sep 17 00:00:00 2001 From: Matthew Endsley Date: Sun, 13 May 2012 20:01:04 -0700 Subject: details for serializing bsdiff_header is left to caller --- bsdiff.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/bsdiff.c b/bsdiff.c index 66ab64e..2c9be29 100644 --- a/bsdiff.c +++ b/bsdiff.c @@ -35,9 +35,9 @@ __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bsdiff/bsdiff.c,v 1.1 2005/08/06 01:59:05 struct bsdiff_header { uint8_t signature[8]; - uint8_t ctrl_block_length[8]; - uint8_t diff_block_length[8]; - uint8_t new_file_length[8]; + uint64_t ctrl_block_length; + uint64_t diff_block_length; + uint64_t new_file_length; }; struct bsdiff_stream @@ -282,7 +282,7 @@ static int bsdiff_internal(const struct bsdiff_request req) ?? ?? Bzip2ed diff block ?? ?? Bzip2ed extra block */ memcpy(req.header->signature,"BSDIFF40",sizeof(req.header->signature)); - offtout(req.newsize, req.header->new_file_length); + req.header->new_file_length = req.newsize; /* Compute the differences, writing ctrl as we go */ scan=0;len=0; @@ -367,7 +367,7 @@ static int bsdiff_internal(const struct bsdiff_request req) filelen += compresslen; /* Compute size of compressed ctrl data */ - offtout(filelen, req.header->ctrl_block_length); + req.header->ctrl_block_length = filelen; /* Write compressed diff data */ filelen = 0; @@ -381,7 +381,7 @@ static int bsdiff_internal(const struct bsdiff_request req) filelen += compresslen; /* Compute size of compressed diff data */ - offtout(filelen, req.header->diff_block_length); + req.header->diff_block_length = filelen; /* Write compressed extra data */ compresslen = writecompressed(req.stream, eb, eblen); @@ -528,6 +528,7 @@ int main(int argc,char *argv[]) uint8_t *old,*new; off_t oldsize,newsize; struct bsdiff_header header; + uint8_t buf[8]; FILE * pf; struct bsdiff_stream stream; bz_stream bz2; @@ -573,7 +574,16 @@ int main(int argc,char *argv[]) err(1, "bsdiff"); if (fseek(pf, 0, SEEK_SET) || - fwrite(&header, sizeof(header), 1, pf) != 1) + fwrite(&header.signature, sizeof(header.signature), 1, pf) != 1) + err(1, "Failed to write header"); + offtout(header.ctrl_block_length, buf); + if (fwrite(buf, sizeof(buf), 1, pf) != 1) + err(1, "Failed to write header"); + offtout(header.diff_block_length, buf); + if (fwrite(buf, sizeof(buf), 1, pf) != 1) + err(1, "Failed to write header"); + offtout(header.new_file_length, buf); + if (fwrite(buf, sizeof(buf), 1, pf) != 1) err(1, "Failed to write header"); if (fclose(pf)) -- cgit v1.2.1