1 /******************************************************************************
2  *
3  *  sysdata.h -
4  *
5  * $Id: sysdata.h 3455 2017-04-24 08:50:31Z scribe $
6  *
7  * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org)
8  *	CrossWire Bible Society
9  *	P. O. Box 2528
10  *	Tempe, AZ  85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 #ifndef SIZEDTYPES_H
24 #define SIZEDTYPES_H
25 /*
26  * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
27  * header files exported to user space
28  */
29 #ifdef USE_AUTOTOOLS
30 #include "config.h"
31 #endif
32 
33 
34 typedef signed char __s8;
35 typedef unsigned char __u8;
36 
37 typedef signed short __s16;
38 typedef unsigned short __u16;
39 
40 typedef signed int __s32;
41 typedef unsigned int __u32;
42 
43 #ifdef OS_ANDROID
44 #elif defined(__GNUC__)
45 __extension__ typedef __signed__ long long __s64;
46 __extension__ typedef unsigned long long __u64;
47 #elif defined(__BORLANDC__)
48 typedef signed __int64 __s64;
49 typedef unsigned __int64 __u64;
50 #else
51 typedef signed long long __s64;
52 typedef unsigned long long __u64;
53 #endif
54 
55 #undef __swswap16
56 #undef __swswap32
57 #undef __swswap64
58 
59 #define __swswap16(x) \
60 	((__u16)( \
61 		(((__u16)(x) & (__u16)0x00ffU) << 8) | \
62 		(((__u16)(x) & (__u16)0xff00U) >> 8) ))
63 
64 
65 #define __swswap32(x) \
66 	((__u32)( \
67 		(((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
68 		(((__u32)(x) & (__u32)0x0000ff00UL) <<  8) | \
69 		(((__u32)(x) & (__u32)0x00ff0000UL) >>  8) | \
70 		(((__u32)(x) & (__u32)0xff000000UL) >> 24) ))
71 
72 
73 #define __swswap64(x) \
74 	((__u64)( \
75 		(__u64)(((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) | \
76 		(__u64)(((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) | \
77 		(__u64)(((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) | \
78 		(__u64)(((__u64)(x) & (__u64)0x00000000ff000000ULL) <<  8) | \
79 		   (__u64)(((__u64)(x) & (__u64)0x000000ff00000000ULL) >>  8) | \
80 		(__u64)(((__u64)(x) & (__u64)0x0000ff0000000000ULL) >> 24) | \
81 		(__u64)(((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) | \
82 		(__u64)(((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56) ))
83 
84 
85 
86 
87 #ifndef WORDS_BIGENDIAN
88 
89 #define swordtoarch16(x) (x)
90 #define swordtoarch32(x) (x)
91 #define swordtoarch64(x) (x)
92 #define archtosword16(x) (x)
93 #define archtosword32(x) (x)
94 #define archtosword64(x) (x)
95 
96 #else
97 
98 #define swordtoarch16(x) __swswap16(x)
99 #define swordtoarch32(x) __swswap32(x)
100 #define swordtoarch64(x) __swswap64(x)
101 #define archtosword16(x) __swswap16(x)
102 #define archtosword32(x) __swswap32(x)
103 #define archtosword64(x) __swswap64(x)
104 
105 
106 #endif
107 
108 
109 #endif
110