Mercurial > libdvdread4.hg
annotate bswap.h @ 21:4aa618ae094f src
Use consistent license headers everywhere: Fix FSF address and boilerplate.
author | diego |
---|---|
date | Sun, 14 Sep 2008 15:42:49 +0000 |
parents | fce16251755c |
children | 447c5319a522 |
rev | line source |
---|---|
3 | 1 #ifndef BSWAP_H_INCLUDED |
2 #define BSWAP_H_INCLUDED | |
3 | |
4 /* | |
5 * Copyright (C) 2000, 2001 Billy Biggs <vektor@dumbterm.net>, | |
6 * Håkan Hjort <d95hjort@dtek.chalmers.se> | |
7 * | |
21
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
8 * This file is part of libdvdread. |
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
9 * |
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
10 * libdvdread is free software; you can redistribute it and/or modify |
3 | 11 * it under the terms of the GNU General Public License as published by |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
21
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
15 * libdvdread is distributed in the hope that it will be useful, |
3 | 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
21
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
20 * You should have received a copy of the GNU General Public License along |
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
21 * with libdvdread; if not, write to the Free Software Foundation, Inc., |
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
3 | 23 */ |
24 | |
25 #include <config.h> | |
26 | |
27 #if defined(WORDS_BIGENDIAN) | |
20 | 28 /* All bigendian systems are fine, just ignore the swaps. */ |
3 | 29 #define B2N_16(x) (void)(x) |
30 #define B2N_32(x) (void)(x) | |
31 #define B2N_64(x) (void)(x) | |
32 | |
20 | 33 #else |
3 | 34 |
35 /* For __FreeBSD_version */ | |
36 #if defined(HAVE_SYS_PARAM_H) | |
37 #include <sys/param.h> | |
38 #endif | |
39 | |
40 #if defined(__linux__) || defined(__GLIBC__) | |
41 #include <byteswap.h> | |
42 #define B2N_16(x) x = bswap_16(x) | |
43 #define B2N_32(x) x = bswap_32(x) | |
44 #define B2N_64(x) x = bswap_64(x) | |
45 | |
46 #elif defined(__APPLE__) | |
47 #include <libkern/OSByteOrder.h> | |
48 #define B2N_16(x) x = OSSwapBigToHostInt16(x) | |
49 #define B2N_32(x) x = OSSwapBigToHostInt32(x) | |
50 #define B2N_64(x) x = OSSwapBigToHostInt64(x) | |
51 | |
52 #elif defined(__NetBSD__) | |
53 #include <sys/endian.h> | |
54 #define B2N_16(x) BE16TOH(x) | |
55 #define B2N_32(x) BE32TOH(x) | |
56 #define B2N_64(x) BE64TOH(x) | |
57 | |
58 #elif defined(__OpenBSD__) | |
59 #include <sys/endian.h> | |
60 #define B2N_16(x) x = swap16(x) | |
61 #define B2N_32(x) x = swap32(x) | |
62 #define B2N_64(x) x = swap64(x) | |
63 | |
64 #elif defined(__FreeBSD__) && __FreeBSD_version >= 470000 | |
65 #include <sys/endian.h> | |
66 #define B2N_16(x) x = be16toh(x) | |
67 #define B2N_32(x) x = be32toh(x) | |
68 #define B2N_64(x) x = be64toh(x) | |
69 | |
20 | 70 /* This is a slow but portable implementation, it has multiple evaluation |
3 | 71 * problems so beware. |
20 | 72 * Old FreeBSD's and Solaris don't have <byteswap.h> or any other such |
73 * functionality! | |
3 | 74 */ |
75 | |
76 #elif defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) || defined(WIN32) || defined(__CYGWIN__) || defined(__BEOS__) | |
77 #define B2N_16(x) \ | |
78 x = ((((x) & 0xff00) >> 8) | \ | |
79 (((x) & 0x00ff) << 8)) | |
80 #define B2N_32(x) \ | |
81 x = ((((x) & 0xff000000) >> 24) | \ | |
82 (((x) & 0x00ff0000) >> 8) | \ | |
83 (((x) & 0x0000ff00) << 8) | \ | |
84 (((x) & 0x000000ff) << 24)) | |
85 #define B2N_64(x) \ | |
86 x = ((((x) & 0xff00000000000000ULL) >> 56) | \ | |
87 (((x) & 0x00ff000000000000ULL) >> 40) | \ | |
88 (((x) & 0x0000ff0000000000ULL) >> 24) | \ | |
89 (((x) & 0x000000ff00000000ULL) >> 8) | \ | |
90 (((x) & 0x00000000ff000000ULL) << 8) | \ | |
91 (((x) & 0x0000000000ff0000ULL) << 24) | \ | |
92 (((x) & 0x000000000000ff00ULL) << 40) | \ | |
93 (((x) & 0x00000000000000ffULL) << 56)) | |
94 | |
95 #else | |
96 | |
97 /* If there isn't a header provided with your system with this functionality | |
98 * add the relevant || define( ) to the portable implementation above. | |
99 */ | |
100 #error "You need to add endian swap macros for you're system" | |
101 | |
102 #endif | |
103 | |
104 #endif /* WORDS_BIGENDIAN */ | |
105 | |
106 #endif /* BSWAP_H_INCLUDED */ |