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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/*
*
* Copyright 1995-1999 Regents of the University of Minnesota
* Portions Copyright 2001 Sistina Software, Inc.
* Copyright Linus Torvalds and others
*
* This is free software released under the GNU General Public License.
* There is no warranty for this software. See the file COPYING for
* details.
*
* See the file AUTHORS for a list of contributors.
*
*/
/*
* Implements Linux kernel endianess conversations for user space.
*/
#ifndef _OSI_ENDIAN_H
#define _OSI_ENDIAN_H
#if defined(__linux__)
#include <features.h> /* here __GLIBC__ etc. is defined */
/* this is necessary to include "endian.h" */
#if (__GLIBC__ >= 2)
#if (__GLIBC_MINOR__ == 0)
#include <bytesex.h>
#endif /* (__GLIBC_MINOR__ == 0) */
#if (__GLIBC_MINOR__ == 1)
#include <endian.h>
#endif /* (__GLIBC_MINOR__ == 1) */
#endif /* (__GLIBC__ >= 2) */
#endif /* defined(__linux__) */
#include "global.h"
#define swab16(x) \
((uint16)( \
(((uint16)(x) & 0x00ffU) << 8) | \
(((uint16)(x) & 0xff00U) >> 8) ))
#define swab32(x) \
((uint32)( \
(((uint32)(x) & (uint32)0x000000ffUL) << 24) | \
(((uint32)(x) & (uint32)0x0000ff00UL) << 8) | \
(((uint32)(x) & (uint32)0x00ff0000UL) >> 8) | \
(((uint32)(x) & (uint32)0xff000000UL) >> 24) ))
#define swab64(x) \
((uint64)( \
(uint64)(((uint64)(x) & (uint64)0x00000000000000ffULL) << 56) | \
(uint64)(((uint64)(x) & (uint64)0x000000000000ff00ULL) << 40) | \
(uint64)(((uint64)(x) & (uint64)0x0000000000ff0000ULL) << 24) | \
(uint64)(((uint64)(x) & (uint64)0x00000000ff000000ULL) << 8) | \
(uint64)(((uint64)(x) & (uint64)0x000000ff00000000ULL) >> 8) | \
(uint64)(((uint64)(x) & (uint64)0x0000ff0000000000ULL) >> 24) | \
(uint64)(((uint64)(x) & (uint64)0x00ff000000000000ULL) >> 40) | \
(uint64)(((uint64)(x) & (uint64)0xff00000000000000ULL) >> 56) ))
#define swab16p(x) swab16(*(x))
#define swab32p(x) swab32(*(x))
#define swab64p(x) swab64(*(x))
#define swab16s(x) do { *(x) = swab16p((x)); } while (0)
#define swab32s(x) do { *(x) = swab32p((x)); } while (0)
#define swab64s(x) do { *(x) = swab64p((x)); } while (0)
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define be16_to_cpus(x) swab16s(x)
#define be32_to_cpus(x) swab32s(x)
#define be64_to_cpus(x) swab64s(x)
#define cpu_to_be16s(x) swab16s(x)
#define cpu_to_be32s(x) swab32s(x)
#define cpu_to_be64s(x) swab64s(x)
#define cpu_to_be16p(x) swab16p(x)
#define cpu_to_be32p(x) swab32p(x)
#define cpu_to_be64p(x) swab64p(x)
#define be16_to_cpup(x) swab16p(x)
#define be32_to_cpup(x) swab32p(x)
#define be64_to_cpup(x) swab64p(x)
#define cpu_to_be16(x) swab16(x)
#define cpu_to_be32(x) swab32(x)
#define cpu_to_be64(x) swab64(x)
#define be16_to_cpu(x) swab16(x)
#define be32_to_cpu(x) swab32(x)
#define be64_to_cpu(x) swab64(x)
#define le16_to_cpus(x) (x)
#define le32_to_cpus(x) (x)
#define le64_to_cpus(x) (x)
#define cpu_to_le16s(x) (x)
#define cpu_to_le32s(x) (x)
#define cpu_to_le64s(x) (x)
#define cpu_to_le16p(x) (*(x))
#define cpu_to_le32p(x) (*(x))
#define cpu_to_le64p(x) (*(x))
#define le16_to_cpup(x) (*(x))
#define le32_to_cpup(x) (*(x))
#define le64_to_cpup(x) (*(x))
#define cpu_to_le16(x) (x)
#define cpu_to_le32(x) (x)
#define cpu_to_le64(x) (x)
#define le16_to_cpu(x) (x)
#define le32_to_cpu(x) (x)
#define le64_to_cpu(x) (x)
#else /* __BYTE_ORDER == __LITTLE_ENDIAN */
#define be16_to_cpus(x) (x)
#define be32_to_cpus(x) (x)
#define be64_to_cpus(x) (x)
#define cpu_to_be16s(x) (x)
#define cpu_to_be32s(x) (x)
#define cpu_to_be64s(x) (x)
#define cpu_to_be16p(x) (*(x))
#define cpu_to_be32p(x) (*(x))
#define cpu_to_be64p(x) (*(x))
#define be16_to_cpup(x) (*(x))
#define be32_to_cpup(x) (*(x))
#define be64_to_cpup(x) (*(x))
#define cpu_to_be16(x) (x)
#define cpu_to_be32(x) (x)
#define cpu_to_be64(x) (x)
#define be16_to_cpu(x) (x)
#define be32_to_cpu(x) (x)
#define be64_to_cpu(x) (x)
#define le16_to_cpus(x) swab16s(x)
#define le32_to_cpus(x) swab32s(x)
#define le64_to_cpus(x) swab64s(x)
#define cpu_to_le16s(x) swab16s(x)
#define cpu_to_le32s(x) swab32s(x)
#define cpu_to_le64s(x) swab64s(x)
#define cpu_to_le16p(x) swab16p(x)
#define cpu_to_le32p(x) swab32p(x)
#define cpu_to_le64p(x) swab64p(x)
#define le16_to_cpup(x) swab16p(x)
#define le32_to_cpup(x) swab32p(x)
#define le64_to_cpup(x) swab64p(x)
#define cpu_to_le16(x) swab16(x)
#define cpu_to_le32(x) swab32(x)
#define cpu_to_le64(x) swab64(x)
#define le16_to_cpu(x) swab16(x)
#define le32_to_cpu(x) swab32(x)
#define le64_to_cpu(x) swab64(x)
#endif /* __BYTE_ORDER == __LITTLE_ENDIAN */
#endif /* _OSI_ENDIAN_H */
|