c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen * Little-endian data access functions.
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen * Copyright (c) 2004 Andrey Panin <pazke@donpac.ru>
e074ffeaee1ce283bd42f167c6810e3d013f8218Timo Sirainen * This software is released under the MIT license.
db14b5bccf7173161d2247efa7df503cd13a66e3Timo Sirainen#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenstatic inline uint16_t read_le16(const void *addr)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenstatic inline uint32_t read_le32(const void *addr)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenstatic inline uint64_t read_le64(const void *addr)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenstatic inline void write_le16(void *addr, const uint16_t value)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenstatic inline void write_le32(void *addr, const uint32_t value)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenstatic inline void write_le64(void *addr, const uint64_t value)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen * Dumb and slow, but byteorder and alignment independent code.
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen#define readb(addr, pos, type) ((type)(*(((uint8_t *) (addr)) + (pos))))
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenstatic inline uint16_t read_le16(const void *addr)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen return readb(addr, 0, uint16_t) | (readb(addr, 1, uint16_t) << 8);
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenstatic inline uint32_t read_le32(const void *addr)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenstatic inline uint64_t read_le64(const void *addr)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen *(((uint8_t *)(addr)) + (pos)) = (uint8_t) (value)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenstatic inline void write_le16(void *addr, const uint16_t value)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenstatic inline void write_le32(void *addr, const uint32_t value)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenstatic inline void write_le64(void *addr, const uint64_t value)