Debian Codegraph @

src/hime-endian.h

raw symbols SCIP
1 /* Copyright (C) 2009 Edward Der-Hua Liu, Hsin-Chu, Taiwan
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation version 2.1
6 * of the License.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18 #define swap_ch(a, b) \
19 do { \
20 char t; \
21 t = *(a); \
22 *(a) = *(b); \
23 *(b) = t; \
24 } while (0)
25
26 #define swap_byte_2(pp) \
27 do { \
28 char *p = (char *) pp; \
29 swap_ch (p, p + 1); \
30 } while (0)
31 #define swap_byte_4(pp) \
32 do { \
33 char *p = (char *) pp; \
34 swap_ch (p, p + 3); \
35 swap_ch (p + 1, p + 2); \
36 } while (0)
37 #define swap_byte_8(pp) \
38 do { \
39 char *p = (char *) pp; \
40 swap_ch (p, p + 7); \
41 swap_ch (p + 1, p + 6); \
42 swap_ch (p + 2, p + 5); \
43 swap_ch (p + 3, p + 4); \
44 } while (0)
45
46 #if __BYTE_ORDER == __BIG_ENDIAN
47 //#warning "big endian"
48 #define to_hime_endian_2(pp) swap_byte_2 (pp)
49 #define to_hime_endian_4(pp) swap_byte_4 (pp)
50 #define to_hime_endian_8(pp) swap_byte_8 (pp)
51 #else
52 #define to_hime_endian_2(pp) \
53 do { \
54 } while (0)
55 #define to_hime_endian_4(pp) \
56 do { \
57 } while (0)
58 #define to_hime_endian_8(pp) \
59 do { \
60 } while (0)
61 #endif