Skip to content

Commit

Permalink
libchdr C89 compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
sonninnos committed Nov 26, 2024
1 parent 498e371 commit 0a79791
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
6 changes: 3 additions & 3 deletions libretro/deps/libchdr/include/libchdr/cdrom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions libretro/deps/libchdr/include/libchdr/chdconfig.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef __CHDCONFIG_H__
#define __CHDCONFIG_H__

#include <retro_inline.h>

/* Configure CHDR features here */
#define WANT_RAW_DATA_SECTOR 1
#define WANT_SUBCODE 1
Expand Down
10 changes: 5 additions & 5 deletions libretro/deps/libchdr/include/libchdr/coretypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <stdint.h>
#include <stdio.h>

#include <retro_inline.h>
#ifdef USE_LIBRETRO_VFS
#include <streams/file_stream_transforms.h>
#endif
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion libretro/deps/libchdr/src/libchdr_cdrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
38 changes: 19 additions & 19 deletions libretro/deps/libchdr/src/libchdr_chd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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];
Expand All @@ -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;
Expand All @@ -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];
Expand All @@ -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;
Expand All @@ -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];
}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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];
}
Expand All @@ -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];
}
Expand All @@ -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;
Expand All @@ -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]);
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0a79791

Please sign in to comment.