endian.h: add BSD extensions when _BSD_SOURCE is defined.
This commit is contained in:
+48
-1
@@ -7,7 +7,9 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <config/HaikuConfig.h>
|
#include <config/HaikuConfig.h>
|
||||||
|
#ifdef _BSD_SOURCE
|
||||||
|
#include <support/ByteOrder.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Defines architecture dependent endian constants.
|
/* Defines architecture dependent endian constants.
|
||||||
* The constant reflects the byte order, "4" is the most
|
* The constant reflects the byte order, "4" is the most
|
||||||
@@ -28,4 +30,49 @@
|
|||||||
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||||
#define __BYTE_ORDER BYTE_ORDER
|
#define __BYTE_ORDER BYTE_ORDER
|
||||||
|
|
||||||
|
#ifdef _BSD_SOURCE
|
||||||
|
|
||||||
|
/*
|
||||||
|
* General byte order swapping functions.
|
||||||
|
*/
|
||||||
|
#define bswap16(x) __swap_int16(x)
|
||||||
|
#define bswap32(x) __swap_int32(x)
|
||||||
|
#define bswap64(x) __swap_int64(x)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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).
|
||||||
|
*/
|
||||||
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||||
|
#define htobe16(x) bswap16((x))
|
||||||
|
#define htobe32(x) bswap32((x))
|
||||||
|
#define htobe64(x) bswap64((x))
|
||||||
|
#define htole16(x) ((uint16_t)(x))
|
||||||
|
#define htole32(x) ((uint32_t)(x))
|
||||||
|
#define htole64(x) ((uint64_t)(x))
|
||||||
|
|
||||||
|
#define be16toh(x) bswap16((x))
|
||||||
|
#define be32toh(x) bswap32((x))
|
||||||
|
#define be64toh(x) bswap64((x))
|
||||||
|
#define le16toh(x) ((uint16_t)(x))
|
||||||
|
#define le32toh(x) ((uint32_t)(x))
|
||||||
|
#define le64toh(x) ((uint64_t)(x))
|
||||||
|
#else /* BYTE_ORDER != LITTLE_ENDIAN */
|
||||||
|
#define htobe16(x) ((uint16_t)(x))
|
||||||
|
#define htobe32(x) ((uint32_t)(x))
|
||||||
|
#define htobe64(x) ((uint64_t)(x))
|
||||||
|
#define htole16(x) bswap16((x))
|
||||||
|
#define htole32(x) bswap32((x))
|
||||||
|
#define htole64(x) bswap64((x))
|
||||||
|
|
||||||
|
#define be16toh(x) ((uint16_t)(x))
|
||||||
|
#define be32toh(x) ((uint32_t)(x))
|
||||||
|
#define be64toh(x) ((uint64_t)(x))
|
||||||
|
#define le16toh(x) bswap16((x))
|
||||||
|
#define le32toh(x) bswap32((x))
|
||||||
|
#define le64toh(x) bswap64((x))
|
||||||
|
#endif /* BYTE_ORDER == LITTLE_ENDIAN */
|
||||||
|
|
||||||
|
#endif /* _BSD_SOURCE */
|
||||||
|
|
||||||
#endif /* _ENDIAN_H_ */
|
#endif /* _ENDIAN_H_ */
|
||||||
|
|||||||
Reference in New Issue
Block a user