Moved file operation out of unpackpld

This commit is contained in:
_ 2018-04-02 01:27:21 -07:00
parent 54ef5e84db
commit 6cf243138e

View File

@ -73,25 +73,26 @@ char *loadfile(const char *fname, unsigned int *s) {
return buf;
}
bool unpackpld (const char *filename) {
bool unpackpld (const char *filedata,
unsigned int filesize,
const char *filename) {
bool status = false;
unsigned int fsize = 0;
char *filedata = loadfile(filename, &fsize);
printf("fsize is %i\n", fsize);
if (filedata != NULL && fsize != 0) {
printf("fsize is %i\n", filesize);
if (filedata != NULL && filesize != 0) {
struct PldHeader *pldh = getpldh(filedata);
splitpld(filedata, pldh, filename, fsize);
free(pldh -> offsets);
free(pldh);
splitpld(filedata, pldh, filename, filesize);
destroypldh(pldh);
status = true;
}
free(filedata);
return status;
}
int main(int argc, char ** argv) {
char *f = argv[1];
unpackpld(f);
unsigned int bufsize = 0;
char *buffer = loadfile(f, &bufsize);
unpackpld(buffer, bufsize, f);
free(buffer);
return 0;
}