00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef LIBDVDREAD_BSWAP_H
00023 #define LIBDVDREAD_BSWAP_H
00024
00025 #include <config.h>
00026
00027 #if HAVE_BIGENDIAN
00028
00029 #define B2N_16(x) (void)(x)
00030 #define B2N_32(x) (void)(x)
00031 #define B2N_64(x) (void)(x)
00032
00033 #else
00034
00035
00036 #if HAVE_SYS_PARAM_H
00037 #include <sys/param.h>
00038 #endif
00039
00040 #if defined(__linux__) || defined(__GLIBC__)
00041 #include <byteswap.h>
00042 #define B2N_16(x) x = bswap_16(x)
00043 #define B2N_32(x) x = bswap_32(x)
00044 #define B2N_64(x) x = bswap_64(x)
00045
00046 #elif defined(__APPLE__)
00047 #include <libkern/OSByteOrder.h>
00048 #define B2N_16(x) x = OSSwapBigToHostInt16(x)
00049 #define B2N_32(x) x = OSSwapBigToHostInt32(x)
00050 #define B2N_64(x) x = OSSwapBigToHostInt64(x)
00051
00052 #elif defined(__NetBSD__)
00053 #include <sys/endian.h>
00054 #define B2N_16(x) BE16TOH(x)
00055 #define B2N_32(x) BE32TOH(x)
00056 #define B2N_64(x) BE64TOH(x)
00057
00058 #elif defined(__OpenBSD__)
00059 #include <sys/endian.h>
00060 #define B2N_16(x) x = swap16(x)
00061 #define B2N_32(x) x = swap32(x)
00062 #define B2N_64(x) x = swap64(x)
00063
00064 #elif defined(__FreeBSD__) && __FreeBSD_version >= 470000
00065 #include <sys/endian.h>
00066 #define B2N_16(x) x = be16toh(x)
00067 #define B2N_32(x) x = be32toh(x)
00068 #define B2N_64(x) x = be64toh(x)
00069
00070
00071
00072
00073
00074
00075
00076 #elif defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) || defined(WIN32) || defined(__CYGWIN__) || defined(__BEOS__) || defined(__OS2__)
00077 #define B2N_16(x) \
00078 x = ((((x) & 0xff00) >> 8) | \
00079 (((x) & 0x00ff) << 8))
00080 #define B2N_32(x) \
00081 x = ((((x) & 0xff000000) >> 24) | \
00082 (((x) & 0x00ff0000) >> 8) | \
00083 (((x) & 0x0000ff00) << 8) | \
00084 (((x) & 0x000000ff) << 24))
00085 #define B2N_64(x) \
00086 x = ((((x) & 0xff00000000000000ULL) >> 56) | \
00087 (((x) & 0x00ff000000000000ULL) >> 40) | \
00088 (((x) & 0x0000ff0000000000ULL) >> 24) | \
00089 (((x) & 0x000000ff00000000ULL) >> 8) | \
00090 (((x) & 0x00000000ff000000ULL) << 8) | \
00091 (((x) & 0x0000000000ff0000ULL) << 24) | \
00092 (((x) & 0x000000000000ff00ULL) << 40) | \
00093 (((x) & 0x00000000000000ffULL) << 56))
00094
00095 #else
00096
00097
00098
00099
00100 #error "You need to add endian swap macros for you're system"
00101
00102 #endif
00103
00104 #endif
00105
00106 #endif