Back to index

glibc  2.9
endian.h
Go to the documentation of this file.
00001 /* Copyright (C) 1992, 1996, 1997, 2000, 2008 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef       _ENDIAN_H
00020 #define       _ENDIAN_H     1
00021 
00022 #include <features.h>
00023 
00024 /* Definitions for byte order, according to significance of bytes,
00025    from low addresses to high addresses.  The value is what you get by
00026    putting '4' in the most significant byte, '3' in the second most
00027    significant byte, '2' in the second least significant byte, and '1'
00028    in the least significant byte, and then writing down one digit for
00029    each byte, starting with the byte at the lowest address at the left,
00030    and proceeding to the byte with the highest address at the right.  */
00031 
00032 #define       __LITTLE_ENDIAN      1234
00033 #define       __BIG_ENDIAN  4321
00034 #define       __PDP_ENDIAN  3412
00035 
00036 /* This file defines `__BYTE_ORDER' for the particular machine.  */
00037 #include <bits/endian.h>
00038 
00039 /* Some machines may need to use a different endianness for floating point
00040    values.  */
00041 #ifndef __FLOAT_WORD_ORDER
00042 # define __FLOAT_WORD_ORDER __BYTE_ORDER
00043 #endif
00044 
00045 #ifdef __USE_BSD
00046 # define LITTLE_ENDIAN      __LITTLE_ENDIAN
00047 # define BIG_ENDIAN  __BIG_ENDIAN
00048 # define PDP_ENDIAN  __PDP_ENDIAN
00049 # define BYTE_ORDER  __BYTE_ORDER
00050 #endif
00051 
00052 #if __BYTE_ORDER == __LITTLE_ENDIAN
00053 # define __LONG_LONG_PAIR(HI, LO) LO, HI
00054 #elif __BYTE_ORDER == __BIG_ENDIAN
00055 # define __LONG_LONG_PAIR(HI, LO) HI, LO
00056 #endif
00057 
00058 
00059 #ifdef __USE_BSD
00060 /* Conversion interfaces.  */
00061 # include <bits/byteswap.h>
00062 
00063 # if __BYTE_ORDER == __LITTLE_ENDIAN
00064 #  define htobe16(x) __bswap_16 (x)
00065 #  define htole16(x) (x)
00066 #  define be16toh(x) __bswap_16 (x)
00067 #  define le16toh(x) (x)
00068 
00069 #  define htobe32(x) __bswap_32 (x)
00070 #  define htole32(x) (x)
00071 #  define be32toh(x) __bswap_32 (x)
00072 #  define le32toh(x) (x)
00073 
00074 #  define htobe64(x) __bswap_64 (x)
00075 #  define htole64(x) (x)
00076 #  define be64toh(x) __bswap_64 (x)
00077 #  define le64toh(x) (x)
00078 # else
00079 #  define htobe16(x) (x)
00080 #  define htole16(x) __bswap_16 (x)
00081 #  define be16toh(x) (x)
00082 #  define le16toh(x) __bswap_16 (x)
00083 
00084 #  define htobe32(x) (x)
00085 #  define htole32(x) __bswap_32 (x)
00086 #  define be32toh(x) (x)
00087 #  define le32toh(x) __bswap_32 (x)
00088 
00089 #  define htobe64(x) (x)
00090 #  define htole64(x) __bswap_64 (x)
00091 #  define be64toh(x) (x)
00092 #  define le64toh(x) __bswap_64 (x)
00093 # endif
00094 #endif
00095 
00096 #endif /* endian.h */