From 8a1f2f5cf2a30c80efea3ba199358f427d5e3822 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 22 Apr 2018 18:36:30 +0200 Subject: [PATCH] Update libretro-common --- libretro-common/formats/libchdr/libchdr_chd.c | 94 ++++++++++--------- .../formats/libchdr/libchdr_flac.c | 3 +- libretro-common/include/libchdr/chd.h | 5 +- libretro-common/include/libchdr/coretypes.h | 10 +- 4 files changed, 55 insertions(+), 57 deletions(-) diff --git a/libretro-common/formats/libchdr/libchdr_chd.c b/libretro-common/formats/libchdr/libchdr_chd.c index af726e9ae4..93e4fbc039 100644 --- a/libretro-common/formats/libchdr/libchdr_chd.c +++ b/libretro-common/formats/libchdr/libchdr_chd.c @@ -52,6 +52,7 @@ #include #include +#include #define TRUE 1 #define FALSE 0 @@ -255,7 +256,7 @@ struct _chd_file { UINT32 cookie; /* cookie, should equal COOKIE_VALUE */ - core_file * file; /* handle to the open core file */ + RFILE * file; /* handle to the open core file */ UINT8 owns_file; /* flag indicating if this file should be closed on chd_close() */ chd_header header; /* header, extracted from file */ @@ -1150,8 +1151,8 @@ static chd_error decompress_v5_map(chd_file* chd, chd_header* header) } /* read the reader */ - core_fseek(chd->file, header->mapoffset, SEEK_SET); - core_fread(chd->file, rawbuf, sizeof(rawbuf)); + filestream_seek(chd->file, header->mapoffset, SEEK_SET); + filestream_read(chd->file, rawbuf, sizeof(rawbuf)); mapbytes = get_bigendian_uint32(&rawbuf[0]); firstoffs = get_bigendian_uint48(&rawbuf[4]); mapcrc = get_bigendian_uint16(&rawbuf[10]); @@ -1164,8 +1165,8 @@ static chd_error decompress_v5_map(chd_file* chd, chd_header* header) if (compressed == NULL) return CHDERR_OUT_OF_MEMORY; - core_fseek(chd->file, header->mapoffset + 16, SEEK_SET); - core_fread(chd->file, compressed, mapbytes); + filestream_seek(chd->file, header->mapoffset + 16, SEEK_SET); + filestream_read(chd->file, compressed, mapbytes); bitbuf = create_bitstream(compressed, sizeof(uint8_t) * mapbytes); if (bitbuf == NULL) { @@ -1317,7 +1318,7 @@ static INLINE void map_extract_old(const UINT8 *base, map_entry *entry, UINT32 h chd_open_file - open a CHD file for access -------------------------------------------------*/ -chd_error chd_open_file(core_file *file, int mode, chd_file *parent, chd_file **chd) +chd_error chd_open_file(RFILE *file, int mode, chd_file *parent, chd_file **chd) { chd_file *newchd = NULL; chd_error err; @@ -1409,13 +1410,13 @@ chd_error chd_open_file(core_file *file, int mode, chd_file *parent, chd_file ** /* find the codec interface */ if (newchd->header.version < 5) { - for (intfnum = 0; intfnum < ARRAY_LENGTH(codec_interfaces); intfnum++) + for (intfnum = 0; intfnum < ARRAY_SIZE(codec_interfaces); intfnum++) if (codec_interfaces[intfnum].compression == newchd->header.compression[0]) { newchd->codecintf[0] = &codec_interfaces[intfnum]; break; } - if (intfnum == ARRAY_LENGTH(codec_interfaces)) + if (intfnum == ARRAY_SIZE(codec_interfaces)) EARLY_EXIT(err = CHDERR_UNSUPPORTED_FORMAT); /* initialize the codec */ @@ -1429,9 +1430,9 @@ chd_error chd_open_file(core_file *file, int mode, chd_file *parent, chd_file ** { int i, decompnum; /* verify the compression types and initialize the codecs */ - for (decompnum = 0; decompnum < ARRAY_LENGTH(newchd->header.compression); decompnum++) + for (decompnum = 0; decompnum < ARRAY_SIZE(newchd->header.compression); decompnum++) { - for (i = 0 ; i < ARRAY_LENGTH(codec_interfaces) ; i++) + for (i = 0 ; i < ARRAY_SIZE(codec_interfaces) ; i++) { if (codec_interfaces[i].compression == newchd->header.compression[decompnum]) { @@ -1496,7 +1497,7 @@ cleanup: chd_error chd_open(const char *filename, int mode, chd_file *parent, chd_file **chd) { chd_error err; - core_file *file = NULL; + RFILE *file = NULL; /* choose the proper mode */ switch(mode) @@ -1510,8 +1511,11 @@ chd_error chd_open(const char *filename, int mode, chd_file *parent, chd_file ** } /* open the file */ - file = core_fopen(filename); - if (file == 0) + file = filestream_open(filename, + RETRO_VFS_FILE_ACCESS_READ, + RETRO_VFS_FILE_ACCESS_HINT_NONE); + + if (!file) { err = CHDERR_FILE_NOT_FOUND; goto cleanup; @@ -1527,25 +1531,25 @@ chd_error chd_open(const char *filename, int mode, chd_file *parent, chd_file ** cleanup: if ((err != CHDERR_NONE) && (file != NULL)) - core_fclose(file); + filestream_close(file); return err; } chd_error chd_precache(chd_file *chd) { - ssize_t size, count; + int64_t size, count; if (!chd->file_cache) { - core_fseek(chd->file, 0, SEEK_END); - size = core_ftell(chd->file); + filestream_seek(chd->file, 0, SEEK_END); + size = filestream_tell(chd->file); if (size <= 0) return CHDERR_INVALID_DATA; chd->file_cache = malloc(size); if (chd->file_cache == NULL) return CHDERR_OUT_OF_MEMORY; - core_fseek(chd->file, 0, SEEK_SET); - count = core_fread(chd->file, chd->file_cache, size); + filestream_seek(chd->file, 0, SEEK_SET); + count = filestream_read(chd->file, chd->file_cache, size); if (count != size) { free(chd->file_cache); @@ -1623,7 +1627,7 @@ void chd_close(chd_file *chd) /* close the file */ if (chd->owns_file && chd->file != NULL) - core_fclose(chd->file); + filestream_close(chd->file); #ifdef NEED_CACHE_HUNK if (PRINTF_MAX_HUNK) printf("Max hunk = %d/%d\n", chd->maxhunk, chd->header.totalhunks); @@ -1641,7 +1645,7 @@ void chd_close(chd_file *chd) core_file -------------------------------------------------*/ -core_file *chd_core_file(chd_file *chd) +RFILE *chd_core_file(chd_file *chd) { return chd->file; } @@ -1768,8 +1772,8 @@ chd_error chd_get_metadata(chd_file *chd, UINT32 searchtag, UINT32 searchindex, /* read the metadata */ outputlen = MIN(outputlen, metaentry.length); - core_fseek(chd->file, metaentry.offset + METADATA_HEADER_SIZE, SEEK_SET); - count = core_fread(chd->file, output, outputlen); + filestream_seek(chd->file, metaentry.offset + METADATA_HEADER_SIZE, SEEK_SET); + count = filestream_read(chd->file, output, outputlen); if (count != outputlen) return CHDERR_READ_ERROR; @@ -1840,11 +1844,11 @@ static chd_error header_validate(const chd_header *header) return CHDERR_INVALID_PARAMETER; /* require a supported compression mechanism */ - for (intfnum = 0; intfnum < ARRAY_LENGTH(codec_interfaces); intfnum++) + for (intfnum = 0; intfnum < ARRAY_SIZE(codec_interfaces); intfnum++) if (codec_interfaces[intfnum].compression == header->compression[0]) break; - if (intfnum == ARRAY_LENGTH(codec_interfaces)) + if (intfnum == ARRAY_SIZE(codec_interfaces)) return CHDERR_INVALID_PARAMETER; /* require a valid hunksize */ @@ -1919,8 +1923,8 @@ static chd_error header_read(chd_file *chd, chd_header *header) return CHDERR_INVALID_FILE; /* seek and read */ - core_fseek(chd->file, 0, SEEK_SET); - count = core_fread(chd->file, rawheader, sizeof(rawheader)); + filestream_seek(chd->file, 0, SEEK_SET); + count = filestream_read(chd->file, rawheader, sizeof(rawheader)); if (count != sizeof(rawheader)) return CHDERR_READ_ERROR; @@ -2069,11 +2073,11 @@ static chd_error hunk_read_into_cache(chd_file *chd, UINT32 hunknum) static UINT8* read_compressed(chd_file *chd, UINT64 offset, size_t size) { - ssize_t bytes; + int64_t bytes; if (chd->file_cache) return chd->file_cache + offset; - core_fseek(chd->file, offset, SEEK_SET); - bytes = core_fread(chd->file, chd->compressed, size); + filestream_seek(chd->file, offset, SEEK_SET); + bytes = filestream_read(chd->file, chd->compressed, size); if (bytes != size) return NULL; return chd->compressed; @@ -2081,14 +2085,14 @@ static UINT8* read_compressed(chd_file *chd, UINT64 offset, size_t size) static chd_error read_uncompressed(chd_file *chd, UINT64 offset, size_t size, UINT8 *dest) { - ssize_t bytes; + int64_t bytes; if (chd->file_cache) { memcpy(dest, chd->file_cache + offset, size); return CHDERR_NONE; } - core_fseek(chd->file, offset, SEEK_SET); - bytes = core_fread(chd->file, dest, size); + filestream_seek(chd->file, offset, SEEK_SET); + bytes = filestream_read(chd->file, dest, size); if (bytes != size) return CHDERR_READ_ERROR; return CHDERR_NONE; @@ -2277,12 +2281,12 @@ static chd_error hunk_read_into_memory(chd_file *chd, UINT32 hunknum, UINT8 *des INTERNAL MAP ACCESS ***************************************************************************/ -static size_t core_fsize(core_file *f) +static size_t core_fsize(RFILE *f) { - long rv,p = ftell(f); - fseek(f, 0, SEEK_END); - rv = ftell(f); - fseek(f, p, SEEK_SET); + int64_t rv, p = filestream_tell(f); + filestream_seek(f, 0, SEEK_END); + rv = filestream_tell(f); + filestream_seek(f, p, SEEK_SET); return rv; } @@ -2315,8 +2319,8 @@ static chd_error map_read(chd_file *chd) entries = MAP_STACK_ENTRIES; /* read that many */ - core_fseek(chd->file, fileoffset, SEEK_SET); - count = core_fread(chd->file, raw_map_entries, entries * entrysize); + filestream_seek(chd->file, fileoffset, SEEK_SET); + count = filestream_read(chd->file, raw_map_entries, entries * entrysize); if (count != entries * entrysize) { err = CHDERR_READ_ERROR; @@ -2344,8 +2348,8 @@ static chd_error map_read(chd_file *chd) } /* verify the cookie */ - core_fseek(chd->file, fileoffset, SEEK_SET); - count = core_fread(chd->file, &cookie, entrysize); + filestream_seek(chd->file, fileoffset, SEEK_SET); + count = filestream_read(chd->file, &cookie, entrysize); if (count != entrysize || memcmp(&cookie, END_OF_LIST_COOKIE, entrysize)) { err = CHDERR_INVALID_FILE; @@ -2385,11 +2389,11 @@ static chd_error metadata_find_entry(chd_file *chd, UINT32 metatag, UINT32 metai while (metaentry->offset != 0) { UINT8 raw_meta_header[METADATA_HEADER_SIZE]; - UINT32 count; + int64_t count; /* read the raw header */ - core_fseek(chd->file, metaentry->offset, SEEK_SET); - count = core_fread(chd->file, raw_meta_header, sizeof(raw_meta_header)); + filestream_seek(chd->file, metaentry->offset, SEEK_SET); + count = filestream_read(chd->file, raw_meta_header, sizeof(raw_meta_header)); if (count != sizeof(raw_meta_header)) break; diff --git a/libretro-common/formats/libchdr/libchdr_flac.c b/libretro-common/formats/libchdr/libchdr_flac.c index 8fe0cf7752..4cc5dc20a4 100644 --- a/libretro-common/formats/libchdr/libchdr_flac.c +++ b/libretro-common/formats/libchdr/libchdr_flac.c @@ -12,6 +12,7 @@ #include #include #include +#include /*************************************************************************** * FLAC DECODER @@ -153,7 +154,7 @@ bool flac_decoder::decode(int16_t **samples, uint32_t num_samples, bool swap_end { /* make sure we don't have too many channels */ int chans = channels(); - if (chans > ARRAY_LENGTH(m_uncompressed_start)) + if (chans > ARRAY_SIZE(m_uncompressed_start)) return false; /* configure the uncompressed buffer */ diff --git a/libretro-common/include/libchdr/chd.h b/libretro-common/include/libchdr/chd.h index 87759ca133..5180d8e3e9 100644 --- a/libretro-common/include/libchdr/chd.h +++ b/libretro-common/include/libchdr/chd.h @@ -47,6 +47,7 @@ extern "C" { #endif #include "coretypes.h" +#include /*************************************************************************** @@ -347,7 +348,7 @@ struct _chd_verify_result /* chd_error chd_create_file(core_file *file, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 compression, chd_file *parent); */ /* open an existing CHD file */ -chd_error chd_open_file(core_file *file, int mode, chd_file *parent, chd_file **chd); +chd_error chd_open_file(RFILE *file, int mode, chd_file *parent, chd_file **chd); chd_error chd_open(const char *filename, int mode, chd_file *parent, chd_file **chd); @@ -358,7 +359,7 @@ chd_error chd_precache(chd_file *chd); void chd_close(chd_file *chd); /* return the associated core_file */ -core_file *chd_core_file(chd_file *chd); +RFILE *chd_core_file(chd_file *chd); /* return an error string for the given CHD error */ const char *chd_error_string(chd_error err); diff --git a/libretro-common/include/libchdr/coretypes.h b/libretro-common/include/libchdr/coretypes.h index 5a769f6a86..2a68a8a4c3 100644 --- a/libretro-common/include/libchdr/coretypes.h +++ b/libretro-common/include/libchdr/coretypes.h @@ -3,8 +3,7 @@ #include #include - -#define ARRAY_LENGTH(x) (sizeof(x)/sizeof(x[0])) +#include typedef uint64_t UINT64; #ifndef OSD_CPU_H @@ -20,11 +19,4 @@ typedef int16_t INT16; typedef int8_t INT8; #endif -#define core_file FILE -#define core_fopen(file) fopen(file, "rb") -#define core_fseek fseek -#define core_fread(fc, buff, len) fread(buff, 1, len, fc) -#define core_fclose fclose -#define core_ftell ftell - #endif