Changeset View
Changeset View
Standalone View
Standalone View
sys/sys/endian.h
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
#define bswap32(x) __bswap32(x) | #define bswap32(x) __bswap32(x) | ||||
#define bswap64(x) __bswap64(x) | #define bswap64(x) __bswap64(x) | ||||
/* | /* | ||||
* Host to big endian, host to little endian, big endian to host, and little | * Host to big endian, host to little endian, big endian to host, and little | ||||
* endian to host byte order functions as detailed in byteorder(9). | * endian to host byte order functions as detailed in byteorder(9). | ||||
*/ | */ | ||||
#if _BYTE_ORDER == _LITTLE_ENDIAN | #if _BYTE_ORDER == _LITTLE_ENDIAN | ||||
#define htobe16(x) bswap16((x)) | #define htobe16(x) __bswap16((x)) | ||||
#define htobe32(x) bswap32((x)) | #define htobe32(x) __bswap32((x)) | ||||
#define htobe64(x) bswap64((x)) | #define htobe64(x) __bswap64((x)) | ||||
#define htole16(x) ((uint16_t)(x)) | #define htole16(x) ((uint16_t)(x)) | ||||
#define htole32(x) ((uint32_t)(x)) | #define htole32(x) ((uint32_t)(x)) | ||||
#define htole64(x) ((uint64_t)(x)) | #define htole64(x) ((uint64_t)(x)) | ||||
#define be16toh(x) bswap16((x)) | #define be16toh(x) __bswap16((x)) | ||||
#define be32toh(x) bswap32((x)) | #define be32toh(x) __bswap32((x)) | ||||
#define be64toh(x) bswap64((x)) | #define be64toh(x) __bswap64((x)) | ||||
#define le16toh(x) ((uint16_t)(x)) | #define le16toh(x) ((uint16_t)(x)) | ||||
#define le32toh(x) ((uint32_t)(x)) | #define le32toh(x) ((uint32_t)(x)) | ||||
#define le64toh(x) ((uint64_t)(x)) | #define le64toh(x) ((uint64_t)(x)) | ||||
#else /* _BYTE_ORDER != _LITTLE_ENDIAN */ | #else /* _BYTE_ORDER != _LITTLE_ENDIAN */ | ||||
#define htobe16(x) ((uint16_t)(x)) | #define htobe16(x) ((uint16_t)(x)) | ||||
#define htobe32(x) ((uint32_t)(x)) | #define htobe32(x) ((uint32_t)(x)) | ||||
#define htobe64(x) ((uint64_t)(x)) | #define htobe64(x) ((uint64_t)(x)) | ||||
#define htole16(x) bswap16((x)) | #define htole16(x) __bswap16((x)) | ||||
#define htole32(x) bswap32((x)) | #define htole32(x) __bswap32((x)) | ||||
#define htole64(x) bswap64((x)) | #define htole64(x) __bswap64((x)) | ||||
#define be16toh(x) ((uint16_t)(x)) | #define be16toh(x) ((uint16_t)(x)) | ||||
#define be32toh(x) ((uint32_t)(x)) | #define be32toh(x) ((uint32_t)(x)) | ||||
#define be64toh(x) ((uint64_t)(x)) | #define be64toh(x) ((uint64_t)(x)) | ||||
#define le16toh(x) bswap16((x)) | #define le16toh(x) __bswap16((x)) | ||||
#define le32toh(x) bswap32((x)) | #define le32toh(x) __bswap32((x)) | ||||
#define le64toh(x) bswap64((x)) | #define le64toh(x) __bswap64((x)) | ||||
#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */ | #endif /* _BYTE_ORDER == _LITTLE_ENDIAN */ | ||||
/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */ | /* Alignment-agnostic encode/decode bytestream to/from little/big endian. */ | ||||
static __inline uint16_t | static __inline uint16_t | ||||
be16dec(const void *pp) | be16dec(const void *pp) | ||||
{ | { | ||||
uint8_t const *p = (uint8_t const *)pp; | uint8_t const *p = (uint8_t const *)pp; | ||||
▲ Show 20 Lines • Show All 103 Lines • Show Last 20 Lines |