C89_BUILD fixes

This commit is contained in:
twinaphex 2016-09-18 18:28:33 +02:00
parent 4e32fb0fd7
commit c2e2d41452
4 changed files with 38 additions and 45 deletions

View file

@ -265,11 +265,12 @@ static int file_archive_extract_cb(const char *name, const char *valid_exts,
int file_archive_parse_file_init(file_archive_transfer_t *state,
const char *file)
{
char *last = NULL;
char path[PATH_MAX_LENGTH] = {0};
strlcpy(path, file, sizeof(path));
char *last = (char*)path_get_archive_delim(path);
last = (char*)path_get_archive_delim(path);
if (last)
*last = '\0';
@ -395,7 +396,7 @@ int file_archive_parse_file_iterate(
if (ret == -1)
state->type = ARCHIVE_TRANSFER_DEINIT_ERROR;
// early return to prevent deinit from never firing
/* early return to prevent deinit from never firing */
return 0;
}
else
@ -622,6 +623,7 @@ int file_archive_compressed_read(
const char * path, void **buf,
const char* optional_filename, ssize_t *length)
{
const struct file_archive_file_backend *backend = NULL;
int ret = 0;
struct string_list *str_list = file_archive_filename_split(path);
@ -647,8 +649,7 @@ int file_archive_compressed_read(
if (str_list->size <= 1)
goto error;
const struct file_archive_file_backend *backend =
file_archive_get_file_backend(str_list->elems[0].data);
backend = file_archive_get_file_backend(str_list->elems[0].data);
*length = backend->compressed_file_read(str_list->elems[0].data,
str_list->elems[1].data, buf, optional_filename);
@ -660,7 +661,7 @@ int file_archive_compressed_read(
return ret;
error:
//RARCH_ERR("Could not extract string and substring from: %s.\n", path);
/* could not extract string and substring. */
string_list_free(str_list);
*length = 0;
return 0;

View file

@ -100,11 +100,9 @@ static int sevenzip_file_read(
allocTempImp.Alloc = SzAllocTemp;
allocTempImp.Free = SzFreeTemp;
/* Could not open 7zip archive? */
if (InFile_Open(&archiveStream.file, path))
{
//RARCH_ERR("Could not open %s as 7z archive\n.", path);
return -1;
}
FileInStream_CreateVTable(&archiveStream);
LookToRead_CreateVTable(&lookStream, False);
@ -211,13 +209,10 @@ static int sevenzip_file_read(
if (!(file_found && res == SZ_OK))
{
/* Error handling */
/*if (!file_found)
RARCH_ERR("%s: %s in %s.\n",
msg_hash_to_str(MSG_FILE_NOT_FOUND),
needle, path);*/
//RARCH_ERR("Failed to open compressed file inside 7zip archive.\n");
/* Error handling
*
* Failed to open compressed file inside 7zip archive.
*/
outsize = -1;
}
@ -270,19 +265,18 @@ static int sevenzip_stream_decompress_data_to_file_iterate(void *data)
static int sevenzip_parse_file_init(file_archive_transfer_t *state,
const char *file)
{
struct sevenzip_context_t *sevenzip_context = NULL;
if (state->archive_size < SEVENZIP_MAGIC_LEN)
return -1;
if (memcmp(state->data, SEVENZIP_MAGIC, SEVENZIP_MAGIC_LEN) != 0)
return -1;
struct sevenzip_context_t *sevenzip_context = sevenzip_stream_new();
sevenzip_context = sevenzip_stream_new();
/* could not open 7zip archive? */
if (InFile_Open(&sevenzip_context->archiveStream.file, file))
{
//RARCH_ERR("Could not open as 7zip archive: %s.\n",path);
return -1;
}
FileInStream_CreateVTable(&sevenzip_context->archiveStream);
LookToRead_CreateVTable(&sevenzip_context->lookStream, False);
@ -291,7 +285,8 @@ static int sevenzip_parse_file_init(file_archive_transfer_t *state,
CrcGenerateTable();
SzArEx_Init(&sevenzip_context->db);
SzArEx_Open(&sevenzip_context->db, &sevenzip_context->lookStream.s, &sevenzip_context->allocImp, &sevenzip_context->allocTempImp);
SzArEx_Open(&sevenzip_context->db, &sevenzip_context->lookStream.s,
&sevenzip_context->allocImp, &sevenzip_context->allocTempImp);
state->stream = sevenzip_context;
@ -314,16 +309,15 @@ static int sevenzip_parse_file_iterate_step_internal(
if (len < PATH_MAX_LENGTH && !file->IsDir)
{
SRes res = SZ_ERROR_FAIL;
char infile[PATH_MAX_LENGTH] = {0};
uint16_t *temp = (uint16_t*)malloc(len * sizeof(uint16_t));
uint16_t *temp = (uint16_t*)malloc(len * sizeof(uint16_t));
if (!temp)
return -1;
SzArEx_GetFileNameUtf16(&sevenzip_context->db, sevenzip_context->index, temp);
SRes res = SZ_ERROR_FAIL;
if (temp)
{
res = utf16_to_char_string(temp, infile, sizeof(infile))
@ -357,6 +351,7 @@ static int sevenzip_parse_file_iterate_step(file_archive_transfer_t *state,
uint32_t csize = 0;
unsigned cmode = 0;
unsigned payload = 0;
struct sevenzip_context_t *sevenzip_context = NULL;
char filename[PATH_MAX_LENGTH] = {0};
int ret = sevenzip_parse_file_iterate_step_internal(state, filename,
&cdata, &cmode, &size, &csize,
@ -369,8 +364,7 @@ static int sevenzip_parse_file_iterate_step(file_archive_transfer_t *state,
csize, size, checksum, userdata))
return 0;
struct sevenzip_context_t *sevenzip_context =
(struct sevenzip_context_t*)state->stream;
sevenzip_context = (struct sevenzip_context_t*)state->stream;
sevenzip_context->index += payload;

View file

@ -238,10 +238,7 @@ static bool zip_file_decompressed_handle(
handle->data, size);
if (handle->real_checksum != crc32)
{
//RARCH_ERR("%s\n", msg_hash_to_str(MSG_INFLATED_CHECKSUM_DID_NOT_MATCH_CRC32));
goto error;
}
if (handle->stream)
free(handle->stream);
@ -279,7 +276,9 @@ static int zip_file_decompressed(
if (name[strlen(name) - 1] == '/' || name[strlen(name) - 1] == '\\')
return 1;
//RARCH_LOG("[deflate] Path: %s, CRC32: 0x%x\n", name, crc32);
#if 0
RARCH_LOG("[deflate] Path: %s, CRC32: 0x%x\n", name, crc32);
#endif
if (strstr(name, st->needle))
{
@ -415,23 +414,23 @@ static int zip_parse_file_iterate_step_internal(
if (signature != CENTRAL_FILE_HEADER_SIGNATURE)
return 0;
*cmode = read_le(state->directory + 10, 2); // compression mode, 0 = store, 8 = deflate
*checksum = read_le(state->directory + 16, 4); // CRC32
*csize = read_le(state->directory + 20, 4); // compressed size
*size = read_le(state->directory + 24, 4); // uncompressed size
*cmode = read_le(state->directory + 10, 2); /* compression mode, 0 = store, 8 = deflate */
*checksum = read_le(state->directory + 16, 4); /* CRC32 */
*csize = read_le(state->directory + 20, 4); /* compressed size */
*size = read_le(state->directory + 24, 4); /* uncompressed size */
namelength = read_le(state->directory + 28, 2); // file name length
extralength = read_le(state->directory + 30, 2); // extra field length
commentlength = read_le(state->directory + 32, 2); // file comment length
namelength = read_le(state->directory + 28, 2); /* file name length */
extralength = read_le(state->directory + 30, 2); /* extra field length */
commentlength = read_le(state->directory + 32, 2); /* file comment length */
if (namelength >= PATH_MAX_LENGTH)
return -1;
memcpy(filename, state->directory + 46, namelength); // file name
memcpy(filename, state->directory + 46, namelength); /* file name */
offset = read_le(state->directory + 42, 4); // relative offset of local file header
offsetNL = read_le(state->data + offset + 26, 2); // file name length
offsetEL = read_le(state->data + offset + 28, 2); // extra field length
offset = read_le(state->directory + 42, 4); /* relative offset of local file header */
offsetNL = read_le(state->data + offset + 26, 2); /* file name length */
offsetEL = read_le(state->data + offset + 28, 2); /* extra field length */
*cdata = state->data + offset + 30 + offsetNL + offsetEL;

View file

@ -713,8 +713,10 @@ static bool init_content_file_extract(
for (i = 0; i < content->size; i++)
{
bool compressed = NULL;
const char *valid_ext = system->info.valid_extensions;
char temp_content[PATH_MAX_LENGTH] = {0};
char new_path[PATH_MAX_LENGTH] = {0};
bool compressed = NULL;
const char *valid_ext = system->info.valid_extensions;
/* Block extract check. */
if (content->elems[i].attr.i & 1)
@ -728,9 +730,6 @@ static bool init_content_file_extract(
if (!compressed)
continue;
char new_path[PATH_MAX_LENGTH] = {0};
char temp_content[PATH_MAX_LENGTH] = {0};
strlcpy(temp_content, content->elems[i].data,
sizeof(temp_content));