diff --git a/libretro-common/file/archive_file.c b/libretro-common/file/archive_file.c index fab1c2b720..52a4de13f6 100644 --- a/libretro-common/file/archive_file.c +++ b/libretro-common/file/archive_file.c @@ -237,7 +237,8 @@ static int file_archive_extract_cb(const char *name, const char *valid_exts, uint32_t checksum, void *userdata) { const char *ext = path_get_extension(name); - struct archive_extract_userdata *data = (struct archive_extract_userdata*)userdata; + struct archive_extract_userdata *data = (struct archive_extract_userdata*) + userdata; /* Extract first file that matches our list. */ if (ext && string_list_find_elem(data->ext, ext)) @@ -264,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'; @@ -382,7 +384,8 @@ int file_archive_parse_file_iterate( break; case ARCHIVE_TRANSFER_ITERATE: { - const struct file_archive_file_backend *backend = file_archive_get_file_backend(file); + const struct file_archive_file_backend *backend = + file_archive_get_file_backend(file); if (backend) { @@ -393,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 @@ -620,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); @@ -645,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); @@ -658,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; @@ -720,39 +723,48 @@ error: return NULL; } -const struct file_archive_file_backend *file_archive_get_zlib_file_backend() +const struct file_archive_file_backend *file_archive_get_zlib_file_backend(void) { +#ifdef HAVE_ZLIB return &zlib_backend; +#else + return NULL; +#endif } -const struct file_archive_file_backend *file_archive_get_7z_file_backend() +const struct file_archive_file_backend *file_archive_get_7z_file_backend(void) { +#ifdef HAVE_7ZIP return &sevenzip_backend; +#else + return NULL; +#endif } const struct file_archive_file_backend* file_archive_get_file_backend(const char *path) { - const char *file_ext = NULL; + const char *file_ext = NULL; + char *last = NULL; char newpath[PATH_MAX_LENGTH] = {0}; strlcpy(newpath, path, sizeof(newpath)); - char *last = (char*)path_get_archive_delim(newpath); + last = (char*)path_get_archive_delim(newpath); if (last) *last = '\0'; file_ext = path_get_extension(newpath); +#ifdef HAVE_7ZIP if (string_is_equal_noncase(file_ext, "7z")) - { return &sevenzip_backend; - } +#endif +#ifdef HAVE_ZLIB if (string_is_equal_noncase(file_ext, "zip")) - { return &zlib_backend; - } +#endif return NULL; } diff --git a/libretro-common/file/archive_file_7z.c b/libretro-common/file/archive_file_7z.c index b0450d5555..4c082f25ed 100644 --- a/libretro-common/file/archive_file_7z.c +++ b/libretro-common/file/archive_file_7z.c @@ -101,11 +101,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); @@ -212,13 +210,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; } @@ -271,19 +266,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); @@ -292,7 +286,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; @@ -315,16 +310,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)) @@ -358,6 +352,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, @@ -370,8 +365,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; diff --git a/libretro-common/file/archive_file_zlib.c b/libretro-common/file/archive_file_zlib.c index 994392ce7d..fd01d306d5 100644 --- a/libretro-common/file/archive_file_zlib.c +++ b/libretro-common/file/archive_file_zlib.c @@ -239,11 +239,9 @@ 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; - } #endif + if (handle->stream) free(handle->stream); @@ -257,8 +255,8 @@ error: handle->stream = NULL; handle->data = NULL; -#endif return false; +#endif } /* Extract the relative path (needle) from a @@ -280,7 +278,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)) { @@ -416,23 +416,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; diff --git a/libretro-common/include/lists/string_list.h b/libretro-common/include/lists/string_list.h index 48bffa8b34..386ceab9ad 100644 --- a/libretro-common/include/lists/string_list.h +++ b/libretro-common/include/lists/string_list.h @@ -44,7 +44,7 @@ struct string_list_elem union string_list_elem_attr attr; }; -struct __attribute__ ((aligned(1))) string_list +struct string_list { struct string_list_elem *elems; size_t size; diff --git a/tasks/task_content.c b/tasks/task_content.c index 770fa42202..5b4e0112e6 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -715,8 +715,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) @@ -730,9 +732,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));