summaryrefslogtreecommitdiffstats
path: root/lib/byte_conversions.h
blob: 2e4cafe901f5ff7cd20e8455fa6ae7f53bf2fa7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Useful byte conversion macros, not available on all platforms.
 * Copyright (C) 2009-2010 Red Hat Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

#ifndef hivex_byteorder_h
#define hivex_byteorder_h

#ifdef HAVE_ENDIAN_H
#include <endian.h>
#endif
#include <byteswap.h>

#if __BYTE_ORDER == __LITTLE_ENDIAN
#ifndef be32toh
#define be32toh(x) bswap_32 (x)
#endif
#ifndef htobe32
#define htobe32(x) bswap_32 (x)
#endif
#ifndef be64toh
#define be64toh(x) bswap_64 (x)
#endif
#ifndef htobe64
#define htobe64(x) bswap_64 (x)
#endif
#ifndef le16toh
#define le16toh(x) (x)
#endif
#ifndef htole16
#define htole16(x) (x)
#endif
#ifndef le32toh
#define le32toh(x) (x)
#endif
#ifndef htole32
#define htole32(x) (x)
#endif
#ifndef le64toh
#define le64toh(x) (x)
#endif
#ifndef htole64
#define htole64(x) (x)
#endif
#else /* __BYTE_ORDER == __BIG_ENDIAN */
#ifndef be32toh
#define be32toh(x) (x)
#endif
#ifndef htobe32
#define htobe32(x) (x)
#endif
#ifndef be64toh
#define be64toh(x) (x)
#endif
#ifndef htobe64
#define htobe64(x) (x)
#endif
#ifndef le16toh
#define le16toh(x) bswap_16 (x)
#endif
#ifndef htole16
#define htole16(x) bswap_16 (x)
#endif
#ifndef le32toh
#define le32toh(x) bswap_32 (x)
#endif
#ifndef htole32
#define htole32(x) bswap_32 (x)
#endif
#ifndef le64toh
#define le64toh(x) bswap_64 (x)
#endif
#ifndef htole64
#define htole64(x) bswap_64 (x)
#endif
#endif /* __BYTE_ORDER == __BIG_ENDIAN */

#endif /* hivex_byteorder_h */