hivex: Add metadata length functions for nodes and values
[hivex.git] / lib / byte_conversions.h
1 /* Useful byte conversion macros, not available on all platforms.
2  * Copyright (C) 2009-2010 Red Hat Inc.
3  *
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.
8  *
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.
13  */
14
15 #ifndef hivex_byteorder_h
16 #define hivex_byteorder_h
17
18 #ifdef HAVE_ENDIAN_H
19 #include <endian.h>
20 #endif
21 #include <byteswap.h>
22
23 #if __BYTE_ORDER == __LITTLE_ENDIAN
24 #ifndef be32toh
25 #define be32toh(x) bswap_32 (x)
26 #endif
27 #ifndef htobe32
28 #define htobe32(x) bswap_32 (x)
29 #endif
30 #ifndef be64toh
31 #define be64toh(x) bswap_64 (x)
32 #endif
33 #ifndef htobe64
34 #define htobe64(x) bswap_64 (x)
35 #endif
36 #ifndef le16toh
37 #define le16toh(x) (x)
38 #endif
39 #ifndef htole16
40 #define htole16(x) (x)
41 #endif
42 #ifndef le32toh
43 #define le32toh(x) (x)
44 #endif
45 #ifndef htole32
46 #define htole32(x) (x)
47 #endif
48 #ifndef le64toh
49 #define le64toh(x) (x)
50 #endif
51 #ifndef htole64
52 #define htole64(x) (x)
53 #endif
54 #else /* __BYTE_ORDER == __BIG_ENDIAN */
55 #ifndef be32toh
56 #define be32toh(x) (x)
57 #endif
58 #ifndef htobe32
59 #define htobe32(x) (x)
60 #endif
61 #ifndef be64toh
62 #define be64toh(x) (x)
63 #endif
64 #ifndef htobe64
65 #define htobe64(x) (x)
66 #endif
67 #ifndef le16toh
68 #define le16toh(x) bswap_16 (x)
69 #endif
70 #ifndef htole16
71 #define htole16(x) bswap_16 (x)
72 #endif
73 #ifndef le32toh
74 #define le32toh(x) bswap_32 (x)
75 #endif
76 #ifndef htole32
77 #define htole32(x) bswap_32 (x)
78 #endif
79 #ifndef le64toh
80 #define le64toh(x) bswap_64 (x)
81 #endif
82 #ifndef htole64
83 #define htole64(x) bswap_64 (x)
84 #endif
85 #endif /* __BYTE_ORDER == __BIG_ENDIAN */
86
87 #endif /* hivex_byteorder_h */