Skip to content
Merged
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
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