blob: 49439ccf8fa91ba451b25f1869c00ced7de45241 [file] [log] [blame]
Randall Spanglercbaf6962010-08-05 16:42:43 -07001/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
Bill Richardsonf1372d92010-06-11 09:15:55 -07006#ifndef VBOOT_REFERENCE_UTILITY_CGPT_ENDIAN_H_
7#define VBOOT_REFERENCE_UTILITY_CGPT_ENDIAN_H_
8
9// Newer distros already have this. For those that don't, we add it here.
David Riley05987b12015-02-05 19:22:49 -080010#ifndef HAVE_MACOS
Bill Richardsonf1372d92010-06-11 09:15:55 -070011#include <endian.h>
David Riley05987b12015-02-05 19:22:49 -080012#endif
Bill Richardsonf1372d92010-06-11 09:15:55 -070013
14#ifndef le16toh
15
David Riley05987b12015-02-05 19:22:49 -080016#ifndef HAVE_MACOS
Bill Richardsonf1372d92010-06-11 09:15:55 -070017# include <byteswap.h>
David Riley05987b12015-02-05 19:22:49 -080018#endif
Bill Richardsonf1372d92010-06-11 09:15:55 -070019
20# if __BYTE_ORDER == __LITTLE_ENDIAN
21# define htobe16(x) __bswap_16 (x)
22# define htole16(x) (x)
23# define be16toh(x) __bswap_16 (x)
24# define le16toh(x) (x)
25
26# define htobe32(x) __bswap_32 (x)
27# define htole32(x) (x)
28# define be32toh(x) __bswap_32 (x)
29# define le32toh(x) (x)
30
31# define htobe64(x) __bswap_64 (x)
32# define htole64(x) (x)
33# define be64toh(x) __bswap_64 (x)
34# define le64toh(x) (x)
35# else
36# define htobe16(x) (x)
37# define htole16(x) __bswap_16 (x)
38# define be16toh(x) (x)
39# define le16toh(x) __bswap_16 (x)
40
41# define htobe32(x) (x)
42# define htole32(x) __bswap_32 (x)
43# define be32toh(x) (x)
44# define le32toh(x) __bswap_32 (x)
45
46# define htobe64(x) (x)
47# define htole64(x) __bswap_64 (x)
48# define be64toh(x) (x)
49# define le64toh(x) __bswap_64 (x)
50# endif
51
52#endif
53#endif // VBOOT_REFERENCE_UTILITY_CGPT_ENDIAN_H_