From 0a797911e5149c266a2b3ea7cf172d1e6bdff823 Mon Sep 17 00:00:00 2001 From: sonninnos Date: Tue, 26 Nov 2024 07:10:53 +0200 Subject: [PATCH] libchdr C89 compliance --- libretro/deps/libchdr/include/libchdr/cdrom.h | 6 +-- .../deps/libchdr/include/libchdr/chdconfig.h | 2 + .../deps/libchdr/include/libchdr/coretypes.h | 10 ++--- libretro/deps/libchdr/src/libchdr_cdrom.c | 2 +- libretro/deps/libchdr/src/libchdr_chd.c | 38 +++++++++---------- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/libretro/deps/libchdr/include/libchdr/cdrom.h b/libretro/deps/libchdr/include/libchdr/cdrom.h index 816e6a5c4..4ceb0b033 100644 --- a/libretro/deps/libchdr/include/libchdr/cdrom.h +++ b/libretro/deps/libchdr/include/libchdr/cdrom.h @@ -72,12 +72,12 @@ void ecc_clear(uint8_t *sector); INLINE FUNCTIONS ***************************************************************************/ -static inline uint32_t msf_to_lba(uint32_t msf) +static INLINE uint32_t msf_to_lba(uint32_t msf) { return ( ((msf&0x00ff0000)>>16) * 60 * 75) + (((msf&0x0000ff00)>>8) * 75) + ((msf&0x000000ff)>>0); } -static inline uint32_t lba_to_msf(uint32_t lba) +static INLINE uint32_t lba_to_msf(uint32_t lba) { uint8_t m, s, f; @@ -96,7 +96,7 @@ static inline uint32_t lba_to_msf(uint32_t lba) * Angelo also says PCE tracks often start playing at the * wrong address.. related? **/ -static inline uint32_t lba_to_msf_alt(int lba) +static INLINE uint32_t lba_to_msf_alt(int lba) { uint32_t ret = 0; diff --git a/libretro/deps/libchdr/include/libchdr/chdconfig.h b/libretro/deps/libchdr/include/libchdr/chdconfig.h index 752038b48..32a112ced 100644 --- a/libretro/deps/libchdr/include/libchdr/chdconfig.h +++ b/libretro/deps/libchdr/include/libchdr/chdconfig.h @@ -1,6 +1,8 @@ #ifndef __CHDCONFIG_H__ #define __CHDCONFIG_H__ +#include + /* Configure CHDR features here */ #define WANT_RAW_DATA_SECTOR 1 #define WANT_SUBCODE 1 diff --git a/libretro/deps/libchdr/include/libchdr/coretypes.h b/libretro/deps/libchdr/include/libchdr/coretypes.h index cb516934a..68946fe9a 100644 --- a/libretro/deps/libchdr/include/libchdr/coretypes.h +++ b/libretro/deps/libchdr/include/libchdr/coretypes.h @@ -3,7 +3,7 @@ #include #include - +#include #ifdef USE_LIBRETRO_VFS #include #endif @@ -45,19 +45,19 @@ typedef struct chd_core_file { int (*fseek)(struct chd_core_file*, int64_t, int); } core_file; -static inline int core_fclose(core_file *fp) { +static INLINE int core_fclose(core_file *fp) { return fp->fclose(fp); } -static inline size_t core_fread(core_file *fp, void *ptr, size_t len) { +static INLINE size_t core_fread(core_file *fp, void *ptr, size_t len) { return fp->fread(ptr, 1, len, fp); } -static inline int core_fseek(core_file* fp, int64_t offset, int whence) { +static INLINE int core_fseek(core_file* fp, int64_t offset, int whence) { return fp->fseek(fp, offset, whence); } -static inline uint64_t core_fsize(core_file *fp) +static INLINE uint64_t core_fsize(core_file *fp) { return fp->fsize(fp); } diff --git a/libretro/deps/libchdr/src/libchdr_cdrom.c b/libretro/deps/libchdr/src/libchdr_cdrom.c index 112ea2e14..43bc9f939 100644 --- a/libretro/deps/libchdr/src/libchdr_cdrom.c +++ b/libretro/deps/libchdr/src/libchdr_cdrom.c @@ -304,7 +304,7 @@ static const uint16_t qoffsets[ECC_Q_NUM_BYTES][ECC_Q_COMP] = *------------------------------------------------- */ -static inline uint8_t ecc_source_byte(const uint8_t *sector, uint32_t offset) +static INLINE uint8_t ecc_source_byte(const uint8_t *sector, uint32_t offset) { /* in mode 2 always treat these as 0 bytes */ return (sector[MODE_OFFSET] == 2 && offset < 4) ? 0x00 : sector[SYNC_OFFSET + SYNC_NUM_BYTES + offset]; diff --git a/libretro/deps/libchdr/src/libchdr_chd.c b/libretro/deps/libchdr/src/libchdr_chd.c index a1dcff78f..c20a16527 100644 --- a/libretro/deps/libchdr/src/libchdr_chd.c +++ b/libretro/deps/libchdr/src/libchdr_chd.c @@ -833,6 +833,7 @@ static void huff_codec_free(void *codec) static chd_error huff_codec_decompress(void *codec, const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) { + uint32_t cur; huff_codec_data* huff_codec = (huff_codec_data*) codec; struct bitstream* bitbuf = create_bitstream(src, complen); @@ -845,7 +846,6 @@ static chd_error huff_codec_decompress(void *codec, const uint8_t *src, uint32_t } // then decode the data - uint32_t cur; for (cur = 0; cur < destlen; cur++) dest[cur] = huffman_decode_one(huff_codec->decoder, bitbuf); bitstream_flush(bitbuf); @@ -1059,6 +1059,9 @@ static void zstd_codec_free(void* codec) */ static chd_error zstd_codec_decompress(void* codec, const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) { + ZSTD_inBuffer input = {src, complen, 0}; + ZSTD_outBuffer output = {dest, destlen, 0 }; + /* initialize */ zstd_codec_data* zstd_codec = (zstd_codec_data*) codec; //reset decompressor @@ -1069,9 +1072,6 @@ static chd_error zstd_codec_decompress(void* codec, const uint8_t *src, uint32_t return CHDERR_DECOMPRESSION_ERROR; } - ZSTD_inBuffer input = {src, complen, 0}; - ZSTD_outBuffer output = {dest, destlen, 0 }; - while ((input.pos < input.size) && (output.pos < output.size)) { zstd_res = ZSTD_decompressStream(zstd_codec->dstream, &output, &input); @@ -1320,7 +1320,7 @@ static const codec_interface codec_interfaces[] = the data stream in bigendian order -------------------------------------------------*/ -static inline uint64_t get_bigendian_uint64_t(const uint8_t *base) +static INLINE uint64_t get_bigendian_uint64_t(const uint8_t *base) { return ((uint64_t)base[0] << 56) | ((uint64_t)base[1] << 48) | ((uint64_t)base[2] << 40) | ((uint64_t)base[3] << 32) | ((uint64_t)base[4] << 24) | ((uint64_t)base[5] << 16) | ((uint64_t)base[6] << 8) | (uint64_t)base[7]; @@ -1331,7 +1331,7 @@ static inline uint64_t get_bigendian_uint64_t(const uint8_t *base) the data stream in bigendian order -------------------------------------------------*/ -static inline void put_bigendian_uint64_t(uint8_t *base, uint64_t value) +static INLINE void put_bigendian_uint64_t(uint8_t *base, uint64_t value) { base[0] = value >> 56; base[1] = value >> 48; @@ -1348,7 +1348,7 @@ static inline void put_bigendian_uint64_t(uint8_t *base, uint64_t value) the data stream in bigendian order -------------------------------------------------*/ -static inline uint64_t get_bigendian_uint48(const uint8_t *base) +static INLINE uint64_t get_bigendian_uint48(const uint8_t *base) { return ((uint64_t)base[0] << 40) | ((uint64_t)base[1] << 32) | ((uint64_t)base[2] << 24) | ((uint64_t)base[3] << 16) | ((uint64_t)base[4] << 8) | (uint64_t)base[5]; @@ -1359,7 +1359,7 @@ static inline uint64_t get_bigendian_uint48(const uint8_t *base) the data stream in bigendian order -------------------------------------------------*/ -static inline void put_bigendian_uint48(uint8_t *base, uint64_t value) +static INLINE void put_bigendian_uint48(uint8_t *base, uint64_t value) { value &= 0xffffffffffff; base[0] = value >> 40; @@ -1374,7 +1374,7 @@ static inline void put_bigendian_uint48(uint8_t *base, uint64_t value) the data stream in bigendian order -------------------------------------------------*/ -static inline uint32_t get_bigendian_uint32_t(const uint8_t *base) +static INLINE uint32_t get_bigendian_uint32_t(const uint8_t *base) { return (base[0] << 24) | (base[1] << 16) | (base[2] << 8) | base[3]; } @@ -1384,7 +1384,7 @@ static inline uint32_t get_bigendian_uint32_t(const uint8_t *base) the data stream in bigendian order -------------------------------------------------*/ -static inline void put_bigendian_uint32_t(uint8_t *base, uint32_t value) +static INLINE void put_bigendian_uint32_t(uint8_t *base, uint32_t value) { base[0] = value >> 24; base[1] = value >> 16; @@ -1397,7 +1397,7 @@ static inline void put_bigendian_uint32_t(uint8_t *base, uint32_t value) the data stream in bigendian order -------------------------------------------------*/ -static inline void put_bigendian_uint24(uint8_t *base, uint32_t value) +static INLINE void put_bigendian_uint24(uint8_t *base, uint32_t value) { value &= 0xffffff; base[0] = value >> 16; @@ -1410,7 +1410,7 @@ static inline void put_bigendian_uint24(uint8_t *base, uint32_t value) the data stream in bigendian order -------------------------------------------------*/ -static inline uint32_t get_bigendian_uint24(const uint8_t *base) +static INLINE uint32_t get_bigendian_uint24(const uint8_t *base) { return (base[0] << 16) | (base[1] << 8) | base[2]; } @@ -1420,7 +1420,7 @@ static inline uint32_t get_bigendian_uint24(const uint8_t *base) the data stream in bigendian order -------------------------------------------------*/ -static inline uint16_t get_bigendian_uint16(const uint8_t *base) +static INLINE uint16_t get_bigendian_uint16(const uint8_t *base) { return (base[0] << 8) | base[1]; } @@ -1430,7 +1430,7 @@ static inline uint16_t get_bigendian_uint16(const uint8_t *base) the data stream in bigendian order -------------------------------------------------*/ -static inline void put_bigendian_uint16(uint8_t *base, uint16_t value) +static INLINE void put_bigendian_uint16(uint8_t *base, uint16_t value) { base[0] = value >> 8; base[1] = value; @@ -1441,7 +1441,7 @@ static inline void put_bigendian_uint16(uint8_t *base, uint16_t value) entry from the datastream -------------------------------------------------*/ -static inline void map_extract(const uint8_t *base, map_entry *entry) +static INLINE void map_extract(const uint8_t *base, map_entry *entry) { entry->offset = get_bigendian_uint64_t(&base[0]); entry->crc = get_bigendian_uint32_t(&base[8]); @@ -1454,7 +1454,7 @@ static inline void map_extract(const uint8_t *base, map_entry *entry) entry to the datastream -------------------------------------------------*/ -static inline void map_assemble(uint8_t *base, map_entry *entry) +static INLINE void map_assemble(uint8_t *base, map_entry *entry) { put_bigendian_uint64_t(&base[0], entry->offset); put_bigendian_uint32_t(&base[8], entry->crc); @@ -1466,7 +1466,7 @@ static inline void map_assemble(uint8_t *base, map_entry *entry) /*------------------------------------------------- map_size_v5 - calculate CHDv5 map size -------------------------------------------------*/ -static inline int map_size_v5(chd_header* header) +static INLINE int map_size_v5(chd_header* header) { return header->hunkcount * header->mapentrybytes; } @@ -1525,7 +1525,7 @@ uint16_t crc16(const void *data, uint32_t length) /*------------------------------------------------- compressed - test if CHD file is compressed +-------------------------------------------------*/ -static inline int chd_compressed(chd_header* header) { +static INLINE int chd_compressed(chd_header* header) { return header->compression[0] != CHD_CODEC_NONE; } @@ -1705,7 +1705,7 @@ static chd_error decompress_v5_map(chd_file* chd, chd_header* header) entry in old format from the datastream -------------------------------------------------*/ -static inline void map_extract_old(const uint8_t *base, map_entry *entry, uint32_t hunkbytes) +static INLINE void map_extract_old(const uint8_t *base, map_entry *entry, uint32_t hunkbytes) { entry->offset = get_bigendian_uint64_t(&base[0]); entry->crc = 0;