Mercurial > hg > forks > bilotrip-mj12
annotate src/platform.h @ 45:d85542c96791
Clean up the build some more, move platform specifics again.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 06 Aug 2013 00:23:45 +0300 |
parents | 785057719d9b |
children |
rev | line source |
---|---|
45
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1 #ifndef MPLATFORM_H |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
2 #define MPLATFORM_H 1 |
0 | 3 |
4 #include <stdlib.h> | |
45
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
5 #ifndef __APPLE__ |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
6 #include <malloc.h> |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
7 #endif |
0 | 8 |
45
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
9 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
10 /* Some platform specifics |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
11 */ |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
12 #if defined(_WIN32) || defined(_WIN64) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
13 # define wcpncpy wcsncpy |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
14 # define wcpcpy wcscpy |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
15 #endif |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
16 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
17 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
18 /* Sized integer types |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
19 */ |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
20 #ifdef _WIN32 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
21 #include <wtypes.h> |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
22 typedef unsigned __int8 Uint8; |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
23 typedef unsigned __int16 Uint16; |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
24 typedef unsigned __int32 Uint32; |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
25 typedef unsigned __int64 Uint64; |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
26 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
27 typedef unsigned __int8 int8_t; |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
28 typedef unsigned __int16 int16_t; |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
29 typedef unsigned __int32 int32_t; |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
30 typedef unsigned __int64 int64_t; |
0 | 31 #else |
32 #include <stdint.h> | |
45
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
33 typedef uint8_t Uint8; |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
34 typedef uint16_t Uint16; |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
35 typedef uint32_t Uint32; |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
36 typedef uint64_t Uint64; |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
37 #endif |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
38 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
39 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
40 /* Define a boolean type |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
41 */ |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
42 #if !defined(FALSE) && !defined(TRUE) && !defined(BOOL) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
43 typedef enum { FALSE = 0, TRUE = 1 } BOOL; |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
44 #endif |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
45 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
46 #ifndef BOOL |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
47 # ifdef bool |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
48 # define BOOL bool |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
49 # else |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
50 # define BOOL int |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
51 # endif |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
52 #endif |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
53 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
54 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
55 /* Endianess swapping macros |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
56 */ |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
57 #define DM_SWAP_16_LE_BE(value) ((Uint16) ( \ |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
58 (Uint16) ((Uint16) (value) >> 8) | \ |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
59 (Uint16) ((Uint16) (value) << 8)) ) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
60 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
61 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
62 #define DM_SWAP_32_LE_BE(value) ((Uint32) ( \ |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
63 (((Uint32) (value) & (Uint32) 0x000000ffU) << 24) | \ |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
64 (((Uint32) (value) & (Uint32) 0x0000ff00U) << 8) | \ |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
65 (((Uint32) (value) & (Uint32) 0x00ff0000U) >> 8) | \ |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
66 (((Uint32) (value) & (Uint32) 0xff000000U) >> 24))) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
67 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
68 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
69 /* Macros that swap only when needed ... |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
70 */ |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
71 #if (BYTEORDER == BIG_ENDIAN) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
72 # define DM_LE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
73 # define DM_LE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
74 # define DM_NATIVE_TO_LE16(value) DM_SWAP_16_LE_BE(value) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
75 # define DM_NATIVE_TO_LE32(value) DM_SWAP_32_LE_BE(value) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
76 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
77 # define DM_BE16_TO_NATIVE(value) ((Uint16) (value)) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
78 # define DM_BE32_TO_NATIVE(value) ((Uint32) (value)) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
79 # define DM_NATIVE_TO_BE16(value) ((Uint16) (value)) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
80 # define DM_NATIVE_TO_BE32(value) ((Uint32) (value)) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
81 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
82 #elif (BYTEORDER == LIL_ENDIAN) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
83 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
84 # define DM_LE16_TO_NATIVE(value) ((Uint16) (value)) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
85 # define DM_LE32_TO_NATIVE(value) ((Uint32) (value)) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
86 # define DM_NATIVE_TO_LE16(value) ((Uint16) (value)) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
87 # define DM_NATIVE_TO_LE32(value) ((Uint32) (value)) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
88 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
89 # define DM_BE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
90 # define DM_BE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
91 # define DM_NATIVE_TO_BE16(value) DM_SWAP_16_LE_BE(value) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
92 # define DM_NATIVE_TO_BE32(value) DM_SWAP_32_LE_BE(value) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
93 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
94 #endif |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
95 |
0 | 96 |
97 #ifdef __cplusplus | |
98 extern "C" { | |
99 #endif | |
100 | |
45
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
101 #if defined(__APPLE__) || defined(_WIN32) || defined(_WIN64) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
102 char * strndup(const char *s, size_t n); |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
103 # pragma warning (disable: 4244) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
104 #endif |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
105 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
106 #if defined(_WIN32) || defined(_WIN64) |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
107 double round(float v); |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
108 #endif |
0 | 109 |
110 #ifdef __cplusplus | |
111 } | |
112 #endif // __cplusplus | |
113 | |
45
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
114 |
d85542c96791
Clean up the build some more, move platform specifics again.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
115 #endif // MPLATFORM_H |