From 732a58277e4d66069d69677ab9ecff086139608a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emanuel=20Kom=C3=ADnek?= Date: Sat, 15 Sep 2018 20:10:15 +0200 Subject: [PATCH] Forwards information about what data block is being written to writedata() callback. --- bsdiff.c | 12 ++++++------ bsdiff.h | 6 +++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bsdiff.c b/bsdiff.c index 628f1c1..4b5de15 100644 --- a/bsdiff.c +++ b/bsdiff.c @@ -185,14 +185,14 @@ static void offtout(int64_t x,uint8_t *buf) if(x<0) buf[7]|=0x80; } -static int64_t writedata(struct bsdiff_stream* stream, const void* buffer, int64_t length) +static int64_t writedata(struct bsdiff_stream* stream, const void* buffer, int64_t length, int type) { int64_t result = 0; while (length > 0) { const int smallsize = (int)MIN(length, INT_MAX); - const int writeresult = stream->write(stream, buffer, smallsize); + const int writeresult = stream->write(stream, buffer, smallsize, type); if (writeresult == -1) { return -1; @@ -297,19 +297,19 @@ static int bsdiff_internal(const struct bsdiff_request req) offtout((pos-lenb)-(lastpos+lenf),buf+16); /* Write control data */ - if (writedata(req.stream, buf, sizeof(buf))) + if (writedata(req.stream, buf, sizeof(buf), BSDIFF_WRITECONTROL)) return -1; /* Write diff data */ for(i=0;i #include -static int bz2_write(struct bsdiff_stream* stream, const void* buffer, int size) +static int bz2_write(struct bsdiff_stream* stream, const void* buffer, int size, int type __attribute__((__unused__))) { int bz2err; BZFILE* bz2; diff --git a/bsdiff.h b/bsdiff.h index b37da5f..54fe6c6 100644 --- a/bsdiff.h +++ b/bsdiff.h @@ -31,13 +31,17 @@ # include # include +#define BSDIFF_WRITECONTROL 0 +#define BSDIFF_WRITEDIFF 1 +#define BSDIFF_WRITEEXTRA 2 + struct bsdiff_stream { void* opaque; void* (*malloc)(size_t size); void (*free)(void* ptr); - int (*write)(struct bsdiff_stream* stream, const void* buffer, int size); + int (*write)(struct bsdiff_stream* stream, const void* buffer, int size, int type); }; int bsdiff(const uint8_t* old, int64_t oldsize, const uint8_t* new, int64_t newsize, struct bsdiff_stream* stream);