hivex: Add HIVEX_OPEN_WRITE flag to allow hive to be opened for writing.
[libguestfs.git] / hivex / 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 #ifdef HAVE_BYTESWAP_H
22 #include <byteswap.h>
23 #endif
24
25 #if __BYTE_ORDER == __LITTLE_ENDIAN
26 #ifndef be32toh
27 #define be32toh(x) __bswap_32 (x)
28 #endif
29 #ifndef htobe32
30 #define htobe32(x) __bswap_32 (x)
31 #endif
32 #ifndef be64toh
33 #define be64toh(x) __bswap_64 (x)
34 #endif
35 #ifndef htobe64
36 #define htobe64(x) __bswap_64 (x)
37 #endif
38 #ifndef le16toh
39 #define le16toh(x) (x)
40 #endif
41 #ifndef htole16
42 #define htole16(x) (x)
43 #endif
44 #ifndef le32toh
45 #define le32toh(x) (x)
46 #endif
47 #ifndef htole32
48 #define htole32(x) (x)
49 #endif
50 #ifndef le64toh
51 #define le64toh(x) (x)
52 #endif
53 #ifndef htole64
54 #define htole64(x) (x)
55 #endif
56 #else /* __BYTE_ORDER == __BIG_ENDIAN */
57 #ifndef be32toh
58 #define be32toh(x) (x)
59 #endif
60 #ifndef htobe32
61 #define htobe32(x) (x)
62 #endif
63 #ifndef be64toh
64 #define be64toh(x) (x)
65 #endif
66 #ifndef htobe64
67 #define htobe64(x) (x)
68 #endif
69 #ifndef le16toh
70 #define le16toh(x) __bswap_16 (x)
71 #endif
72 #ifndef htole16
73 #define htole16(x) __bswap_16 (x)
74 #endif
75 #ifndef le32toh
76 #define le32toh(x) __bswap_32 (x)
77 #endif
78 #ifndef htole32
79 #define htole32(x) __bswap_32 (x)
80 #endif
81 #ifndef le64toh
82 #define le64toh(x) __bswap_64 (x)
83 #endif
84 #ifndef htole64
85 #define htole64(x) __bswap_64 (x)
86 #endif
87 #endif /* __BYTE_ORDER == __BIG_ENDIAN */
88
89 #endif /* hivex_byteorder_h */