mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-26 00:38:55 +05:30
Minor tweak to parameters in splitpld()
This commit is contained in:
parent
6cf243138e
commit
a188a19d77
15
test/main.c
15
test/main.c
@ -21,10 +21,10 @@ bool writedata(const char *basename,
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void splitpld(const char *buffer,
|
void splitpld(const char *filedata,
|
||||||
|
unsigned int filesize,
|
||||||
const struct PldHeader *ph,
|
const struct PldHeader *ph,
|
||||||
const char *name,
|
const char *name) {
|
||||||
unsigned int s) {
|
|
||||||
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,16 +33,17 @@ 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) {
|
||||||
FILE *f = fopen(fname, "rb");
|
FILE *f = fopen(fname, "rb");
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user