26 #ifndef CDIO_BYTESEX_H_ 27 #define CDIO_BYTESEX_H_ 34 #define UINT16_SWAP_LE_BE_C(val) ((uint16_t) ( \ 35 (((uint16_t) (val) & (uint16_t) 0x00ffU) << 8) | \ 36 (((uint16_t) (val) & (uint16_t) 0xff00U) >> 8))) 39 #define UINT32_SWAP_LE_BE_C(val) ((uint32_t) ( \ 40 (((uint32_t) (val) & (uint32_t) 0x000000ffU) << 24) | \ 41 (((uint32_t) (val) & (uint32_t) 0x0000ff00U) << 8) | \ 42 (((uint32_t) (val) & (uint32_t) 0x00ff0000U) >> 8) | \ 43 (((uint32_t) (val) & (uint32_t) 0xff000000U) >> 24))) 46 #define UINT64_SWAP_LE_BE_C(val) ((uint64_t) ( \ 47 (((uint64_t) (val) & (uint64_t) UINT64_C(0x00000000000000ff)) << 56) | \ 48 (((uint64_t) (val) & (uint64_t) UINT64_C(0x000000000000ff00)) << 40) | \ 49 (((uint64_t) (val) & (uint64_t) UINT64_C(0x0000000000ff0000)) << 24) | \ 50 (((uint64_t) (val) & (uint64_t) UINT64_C(0x00000000ff000000)) << 8) | \ 51 (((uint64_t) (val) & (uint64_t) UINT64_C(0x000000ff00000000)) >> 8) | \ 52 (((uint64_t) (val) & (uint64_t) UINT64_C(0x0000ff0000000000)) >> 24) | \ 53 (((uint64_t) (val) & (uint64_t) UINT64_C(0x00ff000000000000)) >> 40) | \ 54 (((uint64_t) (val) & (uint64_t) UINT64_C(0xff00000000000000)) >> 56))) 56 #ifndef UINT16_SWAP_LE_BE 57 # define UINT16_SWAP_LE_BE UINT16_SWAP_LE_BE_C 60 #ifndef UINT32_SWAP_LE_BE 61 # define UINT32_SWAP_LE_BE UINT32_SWAP_LE_BE_C 64 #ifndef UINT64_SWAP_LE_BE 65 # define UINT64_SWAP_LE_BE UINT64_SWAP_LE_BE_C 69 uint16_t uint16_swap_le_be (
const uint16_t val)
75 uint32_t uint32_swap_le_be (
const uint32_t val)
81 uint64_t uint64_swap_le_be (
const uint64_t val)
86 # define UINT8_TO_BE(val) ((uint8_t) (val)) 87 # define UINT8_TO_LE(val) ((uint8_t) (val)) 88 #ifdef WORDS_BIGENDIAN 89 # define UINT16_TO_BE(val) ((uint16_t) (val)) 90 # define UINT16_TO_LE(val) ((uint16_t) UINT16_SWAP_LE_BE(val)) 92 # define UINT32_TO_BE(val) ((uint32_t) (val)) 93 # define UINT32_TO_LE(val) ((uint32_t) UINT32_SWAP_LE_BE(val)) 95 # define UINT64_TO_BE(val) ((uint64_t) (val)) 96 # define UINT64_TO_LE(val) ((uint64_t) UINT64_SWAP_LE_BE(val)) 98 # define UINT16_TO_BE(val) ((uint16_t) UINT16_SWAP_LE_BE(val)) 99 # define UINT16_TO_LE(val) ((uint16_t) (val)) 101 # define UINT32_TO_BE(val) ((uint32_t) UINT32_SWAP_LE_BE(val)) 102 # define UINT32_TO_LE(val) ((uint32_t) (val)) 104 # define UINT64_TO_BE(val) ((uint64_t) UINT64_SWAP_LE_BE(val)) 105 # define UINT64_TO_LE(val) ((uint64_t) (val)) 109 #define UINT8_FROM_BE(val) (UINT8_TO_BE (val)) 110 #define UINT8_FROM_LE(val) (UINT8_TO_LE (val)) 111 #define UINT16_FROM_BE(val) (UINT16_TO_BE (val)) 112 #define UINT16_FROM_LE(val) (UINT16_TO_LE (val)) 113 #define UINT32_FROM_BE(val) (UINT32_TO_BE (val)) 114 #define UINT32_FROM_LE(val) (UINT32_TO_LE (val)) 115 #define UINT64_FROM_BE(val) (UINT64_TO_BE (val)) 116 #define UINT64_FROM_LE(val) (UINT64_TO_LE (val)) 119 #define CVT_TO_FUNC(bits) \ 120 static CDIO_INLINE uint ## bits ## _t \ 121 uint ## bits ## _to_be (uint ## bits ## _t val) \ 122 { return UINT ## bits ## _TO_BE (val); } \ 123 static CDIO_INLINE uint ## bits ## _t \ 124 uint ## bits ## _to_le (uint ## bits ## _t val) \ 125 { return UINT ## bits ## _TO_LE (val); } \ 134 #define uint8_from_be(val) (uint8_to_be (val)) 135 #define uint8_from_le(val) (uint8_to_le (val)) 136 #define uint16_from_be(val) (uint16_to_be (val)) 137 #define uint16_from_le(val) (uint16_to_le (val)) 138 #define uint32_from_be(val) (uint32_to_be (val)) 139 #define uint32_from_le(val) (uint32_to_le (val)) 140 #define uint64_from_be(val) (uint64_to_be (val)) 141 #define uint64_from_le(val) (uint64_to_le (val)) 146 #define to_711(i) uint8_to_le(i) 149 #define from_711(i) uint8_from_le(i) 152 #define to_721(i) uint16_to_le(i) 155 #define from_721(i) uint16_from_le(i) 158 #define to_722(i) uint16_to_be(i) 161 #define from_722(i) uint16_from_be(i) 167 return uint32_swap_le_be(i) | i;
172 from_723 (uint32_t p)
174 uint8_t *u = (uint8_t *) &p;
176 return (u[0] | (u[1] << 8));
180 from_723_with_err (uint32_t p,
bool *err)
182 if (uint32_swap_le_be (p) != p) {
183 cdio_warn (
"from_723: broken byte order");
192 #define to_731(i) uint32_to_le(i) 195 #define from_731(i) uint32_from_le(i) 198 #define to_732(i) uint32_to_be(i) 201 #define from_732(i) uint32_from_be(i) 207 return uint64_swap_le_be(i) | i;
212 from_733 (uint64_t p)
214 uint8_t *u = (uint8_t *) &p;
216 return (u[0] | (u[1] << 8) | (u[2] << 16) | (u[3] << 24));
220 from_733_with_err (uint64_t p,
bool *err)
222 if (uint64_swap_le_be (p) != p) {
223 cdio_warn (
"from_733: broken byte order");
Common type definitions used pervasively in libcdio.
void void void void cdio_warn(const char format[],...) GNUC_PRINTF(1
Header to control logging and level of detail of output.
#define UINT16_SWAP_LE_BE
Definition: bytesex.h:57
#define CDIO_INLINE
Definition: bytesex_asm.h:41
#define UINT32_SWAP_LE_BE
Definition: bytesex.h:61
#define CVT_TO_FUNC(bits)
Definition: bytesex.h:119
Assembly code to handle byte-swapping.
#define UINT32_C(c)
Definition: types.h:82
#define UINT64_SWAP_LE_BE
Definition: bytesex.h:65