Skip to content

Commit a05c79e

Browse files
authored
Merge pull request #4 from drake127/cpp-compatibility
C++ compatibility: Added extern "C" for C++ code.
2 parents e362fbc + a3d3688 commit a05c79e

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

bspatch.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ static int64_t offtin(uint8_t *buf)
4545
return y;
4646
}
4747

48-
int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new, int64_t newsize, struct bspatch_stream* stream)
48+
int bspatch(const uint8_t* source, int64_t sourcesize, uint8_t* target, int64_t targetsize, struct bspatch_stream* stream)
4949
{
5050
uint8_t buf[8];
5151
int64_t oldpos,newpos;
5252
int64_t ctrl[3];
5353
int64_t i;
5454

5555
oldpos=0;newpos=0;
56-
while(newpos<newsize) {
56+
while(newpos<targetsize) {
5757
/* Read control data */
5858
for(i=0;i<=2;i++) {
5959
if (stream->read(stream, buf, 8))
@@ -62,28 +62,28 @@ int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new, int64_t newsize,
6262
};
6363

6464
/* Sanity-check */
65-
if(newpos+ctrl[0]>newsize)
65+
if(newpos+ctrl[0]>targetsize)
6666
return -1;
6767

6868
/* Read diff string */
69-
if (stream->read(stream, new + newpos, ctrl[0]))
69+
if (stream->read(stream, target + newpos, ctrl[0]))
7070
return -1;
7171

7272
/* Add old data to diff string */
7373
for(i=0;i<ctrl[0];i++)
74-
if((oldpos+i>=0) && (oldpos+i<oldsize))
75-
new[newpos+i]+=old[oldpos+i];
74+
if((oldpos+i>=0) && (oldpos+i<sourcesize))
75+
target[newpos+i]+=source[oldpos+i];
7676

7777
/* Adjust pointers */
7878
newpos+=ctrl[0];
7979
oldpos+=ctrl[0];
8080

8181
/* Sanity-check */
82-
if(newpos+ctrl[1]>newsize)
82+
if(newpos+ctrl[1]>targetsize)
8383
return -1;
8484

8585
/* Read extra string */
86-
if (stream->read(stream, new + newpos, ctrl[1]))
86+
if (stream->read(stream, target + newpos, ctrl[1]))
8787
return -1;
8888

8989
/* Adjust pointers */

bspatch.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,21 @@
3030

3131
# include <stdint.h>
3232

33+
#ifdef __cplusplus
34+
extern "C" {
35+
#endif
36+
3337
struct bspatch_stream
3438
{
3539
void* opaque;
3640
int (*read)(const struct bspatch_stream* stream, void* buffer, int length);
3741
};
3842

39-
int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new, int64_t newsize, struct bspatch_stream* stream);
43+
int bspatch(const uint8_t* source, int64_t sourcesize, uint8_t* target, int64_t targetsize, struct bspatch_stream* stream);
44+
45+
#ifdef __cplusplus
46+
}
47+
#endif
4048

4149
#endif
4250

0 commit comments

Comments
 (0)