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