Update unpack-pbp.c

This commit is contained in:
DeadlySystem
2014-03-08 22:58:45 +01:00
parent 0a3a1861a5
commit e538fe7706

View File

@@ -150,6 +150,13 @@ int main(int argc, char *argv[]) {
return -1;
}
// Create the read buffer
buffer = malloc(maxbuffer);
if (buffer == NULL) {
printf("ERROR: Could not allocate the section data buffer. (%d)\n", readsize);
return -1;
}
do {
int readsize;
@@ -161,31 +168,27 @@ int main(int argc, char *argv[]) {
}
size -= readsize;
// Create the read buffer
buffer = malloc(readsize);
if (buffer == NULL) {
printf("ERROR: Could not allocate the section data buffer. (%d)\n", readsize);
return -1;
}
// Read in the data from the PBP
if (fread(buffer, readsize, 1, infile) < 0) {
printf("ERROR: Could not read in the section data.\n");
free(buffer);
return -1;
}
// Write the contents of the buffer to the output file
if (fwrite(buffer, readsize, 1, outfile) < 0) {
printf("ERROR: Could not write out the section data.\n");
free(buffer);
return -1;
}
// Clean up the buffer
free(buffer);
// Repeat if we haven't finished writing the file
} while (size);
// Clean up the buffer
free(buffer);
// Close the output file
if (fclose(outfile) < 0) {
printf("ERROR: Could not close the output file.\n");