From 6cf243138ea271d36aec001ec8ddea986f1aff96 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Mon, 2 Apr 2018 01:27:21 -0700 Subject: [PATCH] Moved file operation out of unpackpld --- test/main.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/test/main.c b/test/main.c index 42020b5..bc7a68b 100644 --- a/test/main.c +++ b/test/main.c @@ -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; }