|
|
1.1 root 1: //
2: // nono
1.1.1.3 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
7: #pragma once
8:
9: #if !defined(_LITTLE_ENDIAN)
10: # define _LITTLE_ENDIAN 1234
11: # define _BIG_ENDIAN 4321
12: #endif
13:
14: #if !defined(_BYTE_ORDER)
15: # if defined(WORDS_BIGENDIAN)
16: # define _BYTE_ORDER _BIG_ENDIAN
17: # else
18: # define _BYTE_ORDER _LITTLE_ENDIAN
19: # endif
20: #endif
21:
1.1.1.2 root 22: // __builtin_bswap* がないような環境があったらその時考える
23: #if !defined(HAVE___BUILTIN_BSWAP16) || \
24: !defined(HAVE___BUILTIN_BSWAP32) || \
25: !defined(HAVE___BUILTIN_BSWAP64)
26: #error No __builtin_bswap*
1.1 root 27: #endif
28:
1.1.1.4 ! root 29: #define bswap16(x) __builtin_bswap16(x)
! 30: #define bswap32(x) __builtin_bswap32(x)
! 31: #define bswap64(x) __builtin_bswap64(x)
! 32:
1.1 root 33: #if _BYTE_ORDER == _BIG_ENDIAN
1.1.1.2 root 34: #define be16toh(x) ((uint16)(x))
35: #define be32toh(x) ((uint32)(x))
36: #define be64toh(x) ((uint64)(x))
1.1.1.4 ! root 37: #define le16toh(x) bswap16((uint16)(x))
! 38: #define le32toh(x) bswap32((uint32)(x))
! 39: #define le64toh(x) bswap64((uint64)(x))
1.1 root 40: #else
1.1.1.4 ! root 41: #define be16toh(x) bswap16((uint16)(x))
! 42: #define be32toh(x) bswap32((uint32)(x))
! 43: #define be64toh(x) bswap64((uint64)(x))
1.1.1.2 root 44: #define le16toh(x) ((uint16)(x))
45: #define le32toh(x) ((uint32)(x))
46: #define le64toh(x) ((uint64)(x))
1.1 root 47: #endif
48:
1.1.1.2 root 49: #define htobe16(x) be16toh(x)
50: #define htobe32(x) be32toh(x)
51: #define htobe64(x) be64toh(x)
1.1 root 52:
1.1.1.2 root 53: #define htole16(x) le16toh(x)
54: #define htole32(x) le32toh(x)
55: #define htole64(x) le64toh(x)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.