(file_extract.c) Cleanups

This commit is contained in:
twinaphex 2015-03-17 06:06:10 +01:00
parent 4df5267ffa
commit 19a2b40a0a

View File

@ -19,8 +19,6 @@
#include <file/file_path.h> #include <file/file_path.h>
#include <compat/strl.h> #include <compat/strl.h>
#include <retro_miscellaneous.h> #include <retro_miscellaneous.h>
#include "general.h"
#include "retroarch_logger.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -42,6 +40,10 @@ struct zlib_file_backend
void (*free)(void *handle); /* Closes, unmaps and frees. */ void (*free)(void *handle); /* Closes, unmaps and frees. */
}; };
#ifndef END_OF_CENTRAL_DIR_SIGNATURE
#define END_OF_CENTRAL_DIR_SIGNATURE 0x06054b50
#endif
#ifdef HAVE_MMAP #ifdef HAVE_MMAP
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -314,7 +316,7 @@ bool zlib_parse_file(const char *file, const char *valid_exts,
{ {
if (footer <= data + 22) if (footer <= data + 22)
GOTO_END_ERROR(); GOTO_END_ERROR();
if (read_le(footer, 4) == 0x06054b50) if (read_le(footer, 4) == END_OF_CENTRAL_DIR_SIGNATURE)
{ {
unsigned comment_len = read_le(footer + 20, 2); unsigned comment_len = read_le(footer + 20, 2);
if (footer + 22 + comment_len == data + zip_size) if (footer + 22 + comment_len == data + zip_size)
@ -383,6 +385,12 @@ struct zip_extract_userdata
bool found_content; bool found_content;
}; };
enum
{
ZLIB_MODE_UNCOMPRESSED = 0,
ZLIB_MODE_DEFLATE = 8,
} zlib_compression_mode;
static int zip_extract_cb(const char *name, const char *valid_exts, static int zip_extract_cb(const char *name, const char *valid_exts,
const uint8_t *cdata, const uint8_t *cdata,
unsigned cmode, uint32_t csize, uint32_t size, unsigned cmode, uint32_t csize, uint32_t size,
@ -406,12 +414,10 @@ static int zip_extract_cb(const char *name, const char *valid_exts,
switch (cmode) switch (cmode)
{ {
/* Uncompressed. */ case ZLIB_MODE_UNCOMPRESSED:
case 0:
data->found_content = write_file(new_path, cdata, size); data->found_content = write_file(new_path, cdata, size);
return false; return false;
/* Deflate. */ case ZLIB_MODE_DEFLATE:
case 8:
if (zlib_inflate_data_to_file(new_path, valid_exts, if (zlib_inflate_data_to_file(new_path, valid_exts,
cdata, csize, size, checksum)) cdata, csize, size, checksum))
{ {