annotate bswap.h @ 40:ce7056d60f01 src

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