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