Skip to content

Cpp compatibility #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions bsdiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion bsdiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
# include <stddef.h>
# include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

struct bsdiff_stream
{
void* opaque;
Expand All @@ -40,6 +44,10 @@ 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
}
#endif

#endif
16 changes: 8 additions & 8 deletions bspatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ 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;
int64_t ctrl[3];
int64_t i;

oldpos=0;newpos=0;
while(newpos<newsize) {
while(newpos<targetsize) {
/* Read control data */
for(i=0;i<=2;i++) {
if (stream->read(stream, buf, 8))
Expand All @@ -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<ctrl[0];i++)
if((oldpos+i>=0) && (oldpos+i<oldsize))
new[newpos+i]+=old[oldpos+i];
if((oldpos+i>=0) && (oldpos+i<sourcesize))
target[newpos+i]+=source[oldpos+i];

/* Adjust pointers */
newpos+=ctrl[0];
oldpos+=ctrl[0];

/* Sanity-check */
if(newpos+ctrl[1]>newsize)
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 */
Expand Down
10 changes: 9 additions & 1 deletion bspatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@

# include <stdint.h>

#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