52# include <arpa/inet.h>
56# define SSIZE_MAX LONG_MAX
74 s = fstat(fileno(file), &hs);
78 if (memcmp(
header->tag,
"MBDIFF10", 8) != 0)
84 header->extralen != uint32_t(hs.st_size))
92 unsigned char *fbuffer, FILE* file)
94 unsigned char *fbufend = fbuffer +
header->slen;
96 unsigned char *buf = (
unsigned char*) malloc(
header->cblen +
105 unsigned char *wb = buf;
109 size_t c = fread(wb, 1,
count, patchFile);
122 unsigned char *diffsrc = buf +
header->cblen;
123 unsigned char *extrasrc = diffsrc +
header->difflen;
126 unsigned char *diffend = extrasrc;
127 unsigned char *extraend = extrasrc +
header->extralen;
131 ctrlsrc->
x =
ntohl(ctrlsrc->
x);
132 ctrlsrc->
y =
ntohl(ctrlsrc->
y);
133 ctrlsrc->
z =
ntohl(ctrlsrc->
z);
135#ifdef DEBUG_bsmedberg
136 printf(
"Applying block:\n"
147 if (fbuffer + ctrlsrc->
x > fbufend ||
148 diffsrc + ctrlsrc->
x > diffend)
153 for (uint32_t
i = 0;
i < ctrlsrc->
x; ++
i)
155 diffsrc[
i] += fbuffer[
i];
157 if ((uint32_t) fwrite(diffsrc, 1, ctrlsrc->
x, file) != ctrlsrc->
x)
162 fbuffer += ctrlsrc->
x;
163 diffsrc += ctrlsrc->
x;
167 if (extrasrc + ctrlsrc->
y > extraend)
172 if ((uint32_t) fwrite(extrasrc, 1, ctrlsrc->
y, file) != ctrlsrc->
y)
177 extrasrc += ctrlsrc->
y;
181 if (fbuffer + ctrlsrc->
z > fbufend)
186 fbuffer += ctrlsrc->
z;
192 while (ctrlsrc < ctrlend);
constexpr sal_Int8 header[]
int MBS_ApplyPatch(const MBSPatchHeader *header, FILE *patchFile, unsigned char *fbuffer, FILE *file)
Apply a patch.
int MBS_ReadHeader(FILE *file, MBSPatchHeader *header)
Read the header of a patch file into the MBSPatchHeader structure.
#define BSPATCH_MEM_ERROR
#define UNEXPECTED_BSPATCH_ERROR
#define WRITE_ERROR_PATCH_FILE
sal_uInt32 ntohl(sal_uInt32 n)