1 /* Useful byte conversion macros, not available on all platforms.
2 * Copyright (C) 2009-2010 Red Hat Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation;
7 * version 2.1 of the License.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
15 #ifndef hivex_byteorder_h
16 #define hivex_byteorder_h
21 #ifdef HAVE_BYTESWAP_H
25 #if __BYTE_ORDER == __LITTLE_ENDIAN
27 #define be32toh(x) __bswap_32 (x)
30 #define htobe32(x) __bswap_32 (x)
33 #define be64toh(x) __bswap_64 (x)
36 #define htobe64(x) __bswap_64 (x)
39 #define le16toh(x) (x)
42 #define htole16(x) (x)
45 #define le32toh(x) (x)
48 #define htole32(x) (x)
51 #define le64toh(x) (x)
54 #define htole64(x) (x)
56 #else /* __BYTE_ORDER == __BIG_ENDIAN */
58 #define be32toh(x) (x)
61 #define htobe32(x) (x)
64 #define be64toh(x) (x)
67 #define htobe64(x) (x)
70 #define le16toh(x) __bswap_16 (x)
73 #define htole16(x) __bswap_16 (x)
76 #define le32toh(x) __bswap_32 (x)
79 #define htole32(x) __bswap_32 (x)
82 #define le64toh(x) __bswap_64 (x)
85 #define htole64(x) __bswap_64 (x)
87 #endif /* __BYTE_ORDER == __BIG_ENDIAN */
89 #endif /* hivex_byteorder_h */