Home | History | Annotate | Download | only in cgpt
      1 /* 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 
      6 #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.
     10 #ifndef HAVE_MACOS
     11 #include <endian.h>
     12 #endif
     13 
     14 #ifndef le16toh
     15 
     16 #ifndef HAVE_MACOS
     17 # include <byteswap.h>
     18 #endif
     19 
     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_
     54