From 7592e72baef4ea97a3cf3e6d689be35e8d54c91e Mon Sep 17 00:00:00 2001 From: bnnm Date: Fri, 17 Jul 2020 19:09:47 +0200 Subject: [PATCH] Make get_xx functions const --- src/meta/ngc_dsp_std.c | 4 ++-- src/meta/redspark.c | 4 ++-- src/meta/txth.c | 4 ++-- src/util.h | 50 +++++++++++++++++++++--------------------- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/meta/ngc_dsp_std.c b/src/meta/ngc_dsp_std.c index b1a9e760..bb785523 100644 --- a/src/meta/ngc_dsp_std.c +++ b/src/meta/ngc_dsp_std.c @@ -29,8 +29,8 @@ struct dsp_header { /* read the above struct; returns nonzero on failure */ static int read_dsp_header_endian(struct dsp_header *header, off_t offset, STREAMFILE *streamFile, int big_endian) { - int32_t (*get_32bit)(uint8_t *) = big_endian ? get_32bitBE : get_32bitLE; - int16_t (*get_16bit)(uint8_t *) = big_endian ? get_16bitBE : get_16bitLE; + int32_t (*get_32bit)(const uint8_t *) = big_endian ? get_32bitBE : get_32bitLE; + int16_t (*get_16bit)(const uint8_t *) = big_endian ? get_16bitBE : get_16bitLE; int i; uint8_t buf[0x4e]; diff --git a/src/meta/redspark.c b/src/meta/redspark.c index fe8f0b93..15c39be8 100644 --- a/src/meta/redspark.c +++ b/src/meta/redspark.c @@ -23,8 +23,8 @@ VGMSTREAM * init_vgmstream_redspark(STREAMFILE *streamFile) { uint32_t key; enum {encsize = 0x1000}; uint8_t buf[encsize]; - int32_t(*get_32bit)(uint8_t *p) = NULL; - int16_t(*get_16bit)(uint8_t *p) = NULL; + int32_t(*get_32bit)(const uint8_t *p) = NULL; + int16_t(*get_16bit)(const uint8_t *p) = NULL; get_16bit = get_16bitBE; get_32bit = get_32bitBE; diff --git a/src/meta/txth.c b/src/meta/txth.c index 1b792352..ff0b847e 100644 --- a/src/meta/txth.c +++ b/src/meta/txth.c @@ -414,8 +414,8 @@ VGMSTREAM* init_vgmstream_txth(STREAMFILE* sf) { /* get coefs */ { - int16_t (*read_16bit)(off_t , STREAMFILE*) = txth.coef_big_endian ? read_16bitBE : read_16bitLE; - int16_t (*get_16bit)(uint8_t * p) = txth.coef_big_endian ? get_16bitBE : get_16bitLE; + int16_t (*read_16bit)(off_t, STREAMFILE*) = txth.coef_big_endian ? read_16bitBE : read_16bitLE; + int16_t (*get_16bit)(const uint8_t* p) = txth.coef_big_endian ? get_16bitBE : get_16bitLE; for (i = 0; i < vgmstream->channels; i++) { if (txth.coef_mode == 0) { /* normal coefs */ diff --git a/src/util.h b/src/util.h index ea7854a6..f40ecb17 100644 --- a/src/util.h +++ b/src/util.h @@ -11,55 +11,55 @@ /* host endian independent multi-byte integer reading */ -static inline int16_t get_16bitBE(uint8_t * p) { +static inline int16_t get_16bitBE(const uint8_t* p) { return (p[0]<<8) | (p[1]); } -static inline int16_t get_16bitLE(uint8_t * p) { +static inline int16_t get_16bitLE(const uint8_t* p) { return (p[0]) | (p[1]<<8); } -static inline int32_t get_32bitBE(uint8_t * p) { +static inline int32_t get_32bitBE(const uint8_t* p) { return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | (p[3]); } -static inline int32_t get_32bitLE(uint8_t * p) { +static inline int32_t get_32bitLE(const uint8_t* p) { return (p[0]) | (p[1]<<8) | (p[2]<<16) | (p[3]<<24); } -static inline int64_t get_64bitBE(uint8_t * p) { +static inline int64_t get_64bitBE(const uint8_t* p) { return (uint64_t)(((uint64_t)p[0]<<56) | ((uint64_t)p[1]<<48) | ((uint64_t)p[2]<<40) | ((uint64_t)p[3]<<32) | ((uint64_t)p[4]<<24) | ((uint64_t)p[5]<<16) | ((uint64_t)p[6]<<8) | ((uint64_t)p[7])); } -static inline int64_t get_64bitLE(uint8_t * p) { +static inline int64_t get_64bitLE(const uint8_t* p) { return (uint64_t)(((uint64_t)p[0]) | ((uint64_t)p[1]<<8) | ((uint64_t)p[2]<<16) | ((uint64_t)p[3]<<24) | ((uint64_t)p[4]<<32) | ((uint64_t)p[5]<<40) | ((uint64_t)p[6]<<48) | ((uint64_t)p[7]<<56)); } /* alias of the above */ -static inline int8_t get_s8 (uint8_t *p) { return ( int8_t)p[0]; } -static inline uint8_t get_u8 (uint8_t *p) { return (uint8_t)p[0]; } -static inline int16_t get_s16le(uint8_t *p) { return ( int16_t)get_16bitLE(p); } -static inline uint16_t get_u16le(uint8_t *p) { return (uint16_t)get_16bitLE(p); } -static inline int16_t get_s16be(uint8_t *p) { return ( int16_t)get_16bitBE(p); } -static inline uint16_t get_u16be(uint8_t *p) { return (uint16_t)get_16bitBE(p); } -static inline int32_t get_s32le(uint8_t *p) { return ( int32_t)get_32bitLE(p); } -static inline uint32_t get_u32le(uint8_t *p) { return (uint32_t)get_32bitLE(p); } -static inline int32_t get_s32be(uint8_t *p) { return ( int32_t)get_32bitBE(p); } -static inline uint32_t get_u32be(uint8_t *p) { return (uint32_t)get_32bitBE(p); } -static inline int64_t get_s64le(uint8_t *p) { return ( int64_t)get_64bitLE(p); } -static inline uint64_t get_u64le(uint8_t *p) { return (uint64_t)get_64bitLE(p); } -static inline int64_t get_s64be(uint8_t *p) { return ( int64_t)get_64bitBE(p); } -static inline uint64_t get_u64be(uint8_t *p) { return (uint64_t)get_64bitBE(p); } +static inline int8_t get_s8 (const uint8_t* p) { return ( int8_t)p[0]; } +static inline uint8_t get_u8 (const uint8_t* p) { return (uint8_t)p[0]; } +static inline int16_t get_s16le(const uint8_t* p) { return ( int16_t)get_16bitLE(p); } +static inline uint16_t get_u16le(const uint8_t* p) { return (uint16_t)get_16bitLE(p); } +static inline int16_t get_s16be(const uint8_t* p) { return ( int16_t)get_16bitBE(p); } +static inline uint16_t get_u16be(const uint8_t* p) { return (uint16_t)get_16bitBE(p); } +static inline int32_t get_s32le(const uint8_t* p) { return ( int32_t)get_32bitLE(p); } +static inline uint32_t get_u32le(const uint8_t* p) { return (uint32_t)get_32bitLE(p); } +static inline int32_t get_s32be(const uint8_t* p) { return ( int32_t)get_32bitBE(p); } +static inline uint32_t get_u32be(const uint8_t* p) { return (uint32_t)get_32bitBE(p); } +static inline int64_t get_s64le(const uint8_t* p) { return ( int64_t)get_64bitLE(p); } +static inline uint64_t get_u64le(const uint8_t* p) { return (uint64_t)get_64bitLE(p); } +static inline int64_t get_s64be(const uint8_t* p) { return ( int64_t)get_64bitBE(p); } +static inline uint64_t get_u64be(const uint8_t* p) { return (uint64_t)get_64bitBE(p); } -void put_8bit(uint8_t * buf, int8_t i); +void put_8bit(uint8_t* buf, int8_t i); -void put_16bitLE(uint8_t * buf, int16_t i); +void put_16bitLE(uint8_t* buf, int16_t i); -void put_32bitLE(uint8_t * buf, int32_t i); +void put_32bitLE(uint8_t* buf, int32_t i); -void put_16bitBE(uint8_t * buf, int16_t i); +void put_16bitBE(uint8_t* buf, int16_t i); -void put_32bitBE(uint8_t * buf, int32_t i); +void put_32bitBE(uint8_t* buf, int32_t i); /* alias of the above */ //TODO: improve #define put_u8 put_8bit