Minor tweak to parameters in splitpld()

This commit is contained in:
_ 2018-04-02 01:55:07 -07:00
parent 6cf243138e
commit a188a19d77

View File

@ -21,10 +21,10 @@ bool writedata(const char *basename,
return status;
}
void splitpld(const char *buffer,
const struct PldHeader *ph,
const char *name,
unsigned int s) {
void splitpld(const char *filedata,
unsigned int filesize,
const struct PldHeader *ph,
const char *name) {
char *wbuffer = NULL; // write buffer that will change.
unsigned int wsize = 0; // size of wbuffer.
unsigned int i;
@ -33,15 +33,16 @@ void splitpld(const char *buffer,
for (i = 0; (i + 1) < (ph -> numOffset) + 1; i++) {
start = ph -> offsets[i];
// the last offset still has some data until the end of file
end = (i == (ph -> numOffset) - 1) ? s : ph -> offsets[i + 1];
end = (i == (ph -> numOffset) - 1) ?
filesize : ph -> offsets[i + 1];
// copy sector to write buffer
wsize = end - start;
wbuffer = (char*)malloc(sizeof(char) * wsize);
memcpy(wbuffer, buffer + start, wsize);
memcpy(wbuffer, filedata + start, wsize);
// create a file.
writedata(name, i, wbuffer, wsize);
free(wbuffer);
}
free(wbuffer);
}
char *loadfile(const char *fname, unsigned int *s) {
@ -80,7 +81,7 @@ bool unpackpld (const char *filedata,
printf("fsize is %i\n", filesize);
if (filedata != NULL && filesize != 0) {
struct PldHeader *pldh = getpldh(filedata);
splitpld(filedata, pldh, filename, filesize);
splitpld(filedata, filesize, pldh, filename);
destroypldh(pldh);
status = true;
}