Path: blob/main/system/lib/libc/musl/include/endian.h
6170 views
#ifndef _ENDIAN_H1#define _ENDIAN_H23#include <features.h>45#define __NEED_uint16_t6#define __NEED_uint32_t7#define __NEED_uint64_t89#include <bits/alltypes.h>1011#define __PDP_ENDIAN 34121213#define BIG_ENDIAN __BIG_ENDIAN14#define LITTLE_ENDIAN __LITTLE_ENDIAN15#define PDP_ENDIAN __PDP_ENDIAN16#define BYTE_ORDER __BYTE_ORDER1718static __inline uint16_t __bswap16(uint16_t __x)19{20return __x<<8 | __x>>8;21}2223static __inline uint32_t __bswap32(uint32_t __x)24{25return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24;26}2728static __inline uint64_t __bswap64(uint64_t __x)29{30return __bswap32(__x)+0ULL<<32 | __bswap32(__x>>32);31}3233#if __BYTE_ORDER == __LITTLE_ENDIAN34#define htobe16(x) __bswap16(x)35#define be16toh(x) __bswap16(x)36#define htobe32(x) __bswap32(x)37#define be32toh(x) __bswap32(x)38#define htobe64(x) __bswap64(x)39#define be64toh(x) __bswap64(x)40#define htole16(x) (uint16_t)(x)41#define le16toh(x) (uint16_t)(x)42#define htole32(x) (uint32_t)(x)43#define le32toh(x) (uint32_t)(x)44#define htole64(x) (uint64_t)(x)45#define le64toh(x) (uint64_t)(x)46#else47#define htobe16(x) (uint16_t)(x)48#define be16toh(x) (uint16_t)(x)49#define htobe32(x) (uint32_t)(x)50#define be32toh(x) (uint32_t)(x)51#define htobe64(x) (uint64_t)(x)52#define be64toh(x) (uint64_t)(x)53#define htole16(x) __bswap16(x)54#define le16toh(x) __bswap16(x)55#define htole32(x) __bswap32(x)56#define le32toh(x) __bswap32(x)57#define htole64(x) __bswap64(x)58#define le64toh(x) __bswap64(x)59#endif6061#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)62#if __BYTE_ORDER == __LITTLE_ENDIAN63#define betoh16(x) __bswap16(x)64#define betoh32(x) __bswap32(x)65#define betoh64(x) __bswap64(x)66#define letoh16(x) (uint16_t)(x)67#define letoh32(x) (uint32_t)(x)68#define letoh64(x) (uint64_t)(x)69#else70#define betoh16(x) (uint16_t)(x)71#define betoh32(x) (uint32_t)(x)72#define betoh64(x) (uint64_t)(x)73#define letoh16(x) __bswap16(x)74#define letoh32(x) __bswap32(x)75#define letoh64(x) __bswap64(x)76#endif77#endif7879#endif808182