| 1 | /* machine/endian.h (emx+gcc) (freebsd 5.0 inspired) */
|
|---|
| 2 |
|
|---|
| 3 | #ifndef _MACHINE_ENDIAN_H
|
|---|
| 4 | #define _MACHINE_ENDIAN_H
|
|---|
| 5 |
|
|---|
| 6 | #include <386/endian.h>
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | /** NOTE this is actually sys/endian.h! */
|
|---|
| 10 |
|
|---|
| 11 | #ifndef _UINT16_T_DECLARED
|
|---|
| 12 | typedef __uint16_t uint16_t;
|
|---|
| 13 | #define _UINT16_T_DECLARED
|
|---|
| 14 | #endif
|
|---|
| 15 |
|
|---|
| 16 | #ifndef _UINT32_T_DECLARED
|
|---|
| 17 | typedef __uint32_t uint32_t;
|
|---|
| 18 | #define _UINT32_T_DECLARED
|
|---|
| 19 | #endif
|
|---|
| 20 |
|
|---|
| 21 | #ifndef _UINT64_T_DECLARED
|
|---|
| 22 | typedef __uint64_t uint64_t;
|
|---|
| 23 | #define _UINT64_T_DECLARED
|
|---|
| 24 | #endif
|
|---|
| 25 |
|
|---|
| 26 | /*
|
|---|
| 27 | * General byte order swapping functions.
|
|---|
| 28 | */
|
|---|
| 29 | #define bswap16(x) __bswap16(x)
|
|---|
| 30 | #define bswap32(x) __bswap32(x)
|
|---|
| 31 | #define bswap64(x) __bswap64(x)
|
|---|
| 32 |
|
|---|
| 33 | /*
|
|---|
| 34 | * Host to big endian, host to little endian, big endian to host, and little
|
|---|
| 35 | * endian to host byte order functions as detailed in byteorder(9).
|
|---|
| 36 | */
|
|---|
| 37 | #if _BYTE_ORDER == _LITTLE_ENDIAN
|
|---|
| 38 | #define htobe16(x) bswap16((x))
|
|---|
| 39 | #define htobe32(x) bswap32((x))
|
|---|
| 40 | #define htobe64(x) bswap64((x))
|
|---|
| 41 | #define htole16(x) ((uint16_t)(x))
|
|---|
| 42 | #define htole32(x) ((uint32_t)(x))
|
|---|
| 43 | #define htole64(x) ((uint64_t)(x))
|
|---|
| 44 |
|
|---|
| 45 | #define be16toh(x) bswap16((x))
|
|---|
| 46 | #define be32toh(x) bswap32((x))
|
|---|
| 47 | #define be64toh(x) bswap64((x))
|
|---|
| 48 | #define le16toh(x) ((uint16_t)(x))
|
|---|
| 49 | #define le32toh(x) ((uint32_t)(x))
|
|---|
| 50 | #define le64toh(x) ((uint64_t)(x))
|
|---|
| 51 | #else /* _BYTE_ORDER != _LITTLE_ENDIAN */
|
|---|
| 52 | #define htobe16(x) ((uint16_t)(x))
|
|---|
| 53 | #define htobe32(x) ((uint32_t)(x))
|
|---|
| 54 | #define htobe64(x) ((uint64_t)(x))
|
|---|
| 55 | #define htole16(x) bswap16((x))
|
|---|
| 56 | #define htole32(x) bswap32((x))
|
|---|
| 57 | #define htole64(x) bswap64((x))
|
|---|
| 58 |
|
|---|
| 59 | #define be16toh(x) ((uint16_t)(x))
|
|---|
| 60 | #define be32toh(x) ((uint32_t)(x))
|
|---|
| 61 | #define be64toh(x) ((uint64_t)(x))
|
|---|
| 62 | #define le16toh(x) bswap16((x))
|
|---|
| 63 | #define le32toh(x) bswap32((x))
|
|---|
| 64 | #define le64toh(x) bswap64((x))
|
|---|
| 65 | #endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
|
|---|
| 66 |
|
|---|
| 67 | #endif /* not _MACHINE_ENDIAN_H */
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|