(decompress) Cleanups

This commit is contained in:
twinaphex 2015-06-14 19:37:24 +02:00
parent c5958e2d49
commit a7f1e43d81
2 changed files with 25 additions and 24 deletions

View File

@ -100,8 +100,7 @@ static Bool Utf16_To_Utf8(uint8_t *dest, size_t *destLen,
dest[destPos] = (char)(0x80
+ ((value >> (6 * numAdds)) & 0x3F));
destPos++;
}
while (numAdds != 0);
}while (numAdds != 0);
}
*destLen = destPos;
return False;
@ -261,7 +260,7 @@ int read_7zip_file(
SzArEx_GetFileNameUtf16(&db, i, temp);
res = ConvertUtf16toCharString(temp,infile);
if (strcmp(infile,relative_path) == 0)
if (!strcmp(infile, relative_path))
{
/* C LZMA SDK does not support chunked extraction - see here:
* sourceforge.net/p/sevenzip/discussion/45798/thread/6fb59aaf/
@ -409,7 +408,8 @@ struct string_list *compressed_7zip_file_list_new(const char *path,
{
free(temp);
tempSize = len;
temp = (uint16_t *)malloc(tempSize * sizeof(temp[0]));
temp = (uint16_t *)malloc(tempSize * sizeof(temp[0]));
if (temp == 0)
{
res = SZ_ERROR_MEM;

View File

@ -19,10 +19,11 @@
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <string.h>
#include <retro_miscellaneous.h>
#include <file/file_path.h>
#include "zip_support.h"
#include "../deps/zlib/unzip.h"
@ -92,7 +93,7 @@ int read_zip_file(const char *archive_path,
{
/* We skip directories */
}
else if (!strcmp(filename,relative_path))
else if (!strcmp(filename, relative_path))
{
/* We found the correct file in the zip,
* now extract it to *buf. */
@ -103,7 +104,24 @@ int read_zip_file(const char *archive_path,
goto error;
}
if (optional_outfile != 0)
if (optional_outfile == 0)
{
/* Allocate outbuffer */
*buf = malloc(file_info.uncompressed_size + 1 );
bytes_read = unzReadCurrentFile(zipfile, *buf, file_info.uncompressed_size);
if (bytes_read != (ssize_t)file_info.uncompressed_size)
{
RARCH_ERR(
"Tried to read %d bytes, but only got %d of file %s in ZIP %s.\n",
(unsigned int) file_info.uncompressed_size, (int)bytes_read,
relative_path, archive_path);
free(*buf);
goto close;
}
((char*)(*buf))[file_info.uncompressed_size] = '\0';
}
else
{
char read_buffer[RARCH_ZIP_SUPPORT_BUFFER_SIZE_MAX] = {0};
FILE* outsink = fopen(optional_outfile,"wb");
@ -135,23 +153,6 @@ int read_zip_file(const char *archive_path,
fclose(outsink);
}
else
{
/* Allocate outbuffer */
*buf = malloc(file_info.uncompressed_size + 1 );
bytes_read = unzReadCurrentFile(zipfile, *buf, file_info.uncompressed_size);
if (bytes_read != (ssize_t)file_info.uncompressed_size)
{
RARCH_ERR(
"Tried to read %d bytes, but only got %d of file %s in ZIP %s.\n",
(unsigned int) file_info.uncompressed_size, (int)bytes_read,
relative_path, archive_path);
free(*buf);
goto close;
}
((char*)(*buf))[file_info.uncompressed_size] = '\0';
}
finished_reading = true;
}