From 8bf68dc87cc50f4ee9db4bc2d1efd632b6a2e877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emanuel=20Kom=C3=ADnek?= Date: Sat, 15 Sep 2018 19:48:28 +0200 Subject: [PATCH 1/3] C++ compatibility: Added extern "C" for C++ code. --- bsdiff.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bsdiff.h b/bsdiff.h index b37da5f..b325c7f 100644 --- a/bsdiff.h +++ b/bsdiff.h @@ -31,6 +31,10 @@ # include # include +#ifdef __cplusplus +extern "C" { +#endif + struct bsdiff_stream { void* opaque; @@ -42,4 +46,8 @@ struct bsdiff_stream int bsdiff(const uint8_t* old, int64_t oldsize, const uint8_t* new, int64_t newsize, struct bsdiff_stream* stream); +#ifdef __cplusplus +} +#endif + #endif From 0752124ed9b6c8e7fe94265518889c1474d28558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emanuel=20Kom=C3=ADnek?= Date: Sat, 15 Sep 2018 19:49:42 +0200 Subject: [PATCH 2/3] C++ compatibility: "new" is reserved word in C++, thus I renamed old->source and new->target. --- bsdiff.c | 14 +++++++------- bsdiff.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bsdiff.c b/bsdiff.c index 628f1c1..0165b0e 100644 --- a/bsdiff.c +++ b/bsdiff.c @@ -321,24 +321,24 @@ static int bsdiff_internal(const struct bsdiff_request req) return 0; } -int bsdiff(const uint8_t* old, int64_t oldsize, const uint8_t* new, int64_t newsize, struct bsdiff_stream* stream) +int bsdiff(const uint8_t* source, int64_t sourcesize, const uint8_t* target, int64_t targetsize, struct bsdiff_stream* stream) { int result; struct bsdiff_request req; - if((req.I=stream->malloc((oldsize+1)*sizeof(int64_t)))==NULL) + if((req.I=stream->malloc((sourcesize+1)*sizeof(int64_t)))==NULL) return -1; - if((req.buffer=stream->malloc(newsize+1))==NULL) + if((req.buffer=stream->malloc(targetsize+1))==NULL) { stream->free(req.I); return -1; } - req.old = old; - req.oldsize = oldsize; - req.new = new; - req.newsize = newsize; + req.old = source; + req.oldsize = sourcesize; + req.new = target; + req.newsize = targetsize; req.stream = stream; result = bsdiff_internal(req); diff --git a/bsdiff.h b/bsdiff.h index b325c7f..1fcd683 100644 --- a/bsdiff.h +++ b/bsdiff.h @@ -44,7 +44,7 @@ struct bsdiff_stream int (*write)(struct bsdiff_stream* stream, const void* buffer, int size); }; -int bsdiff(const uint8_t* old, int64_t oldsize, const uint8_t* new, int64_t newsize, struct bsdiff_stream* stream); +int bsdiff(const uint8_t* source, int64_t sourcesize, const uint8_t* target, int64_t targetsize, struct bsdiff_stream* stream); #ifdef __cplusplus } From a3d3688cb717be296aac05d3df0ea9ee0d536386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emanuel=20Kom=C3=ADnek?= Date: Sun, 16 Sep 2018 18:49:00 +0200 Subject: [PATCH 3/3] C++ compatibility: Added extern "C" for C++ code. C++ compatibility: "new" is reserved word in C++, thus I renamed old->source and new->target. --- bspatch.c | 16 ++++++++-------- bspatch.h | 10 +++++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/bspatch.c b/bspatch.c index b544914..28830e1 100644 --- a/bspatch.c +++ b/bspatch.c @@ -45,7 +45,7 @@ static int64_t offtin(uint8_t *buf) return y; } -int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new, int64_t newsize, struct bspatch_stream* stream) +int bspatch(const uint8_t* source, int64_t sourcesize, uint8_t* target, int64_t targetsize, struct bspatch_stream* stream) { uint8_t buf[8]; int64_t oldpos,newpos; @@ -53,7 +53,7 @@ int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new, int64_t newsize, int64_t i; oldpos=0;newpos=0; - while(newposread(stream, buf, 8)) @@ -62,28 +62,28 @@ int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new, int64_t newsize, }; /* Sanity-check */ - if(newpos+ctrl[0]>newsize) + if(newpos+ctrl[0]>targetsize) return -1; /* Read diff string */ - if (stream->read(stream, new + newpos, ctrl[0])) + if (stream->read(stream, target + newpos, ctrl[0])) return -1; /* Add old data to diff string */ for(i=0;i=0) && (oldpos+i=0) && (oldpos+inewsize) + if(newpos+ctrl[1]>targetsize) return -1; /* Read extra string */ - if (stream->read(stream, new + newpos, ctrl[1])) + if (stream->read(stream, target + newpos, ctrl[1])) return -1; /* Adjust pointers */ diff --git a/bspatch.h b/bspatch.h index 099c36e..e713de7 100644 --- a/bspatch.h +++ b/bspatch.h @@ -30,13 +30,21 @@ # include +#ifdef __cplusplus +extern "C" { +#endif + struct bspatch_stream { void* opaque; int (*read)(const struct bspatch_stream* stream, void* buffer, int length); }; -int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new, int64_t newsize, struct bspatch_stream* stream); +int bspatch(const uint8_t* source, int64_t sourcesize, uint8_t* target, int64_t targetsize, struct bspatch_stream* stream); + +#ifdef __cplusplus +} +#endif #endif