Mercurial > hg > forks > bilotrip-mj12
annotate src/mplatform.h @ 37:1db62040204e
Combine some headers to single mplatform.h
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 05 Aug 2013 21:53:33 +0300 |
parents | src/mtypes.h@bef14a3387a1 |
children |
rev | line source |
---|---|
37
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
1 #ifndef MPLATFORM_H |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
2 #define MPLATFORM_H 1 |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
3 |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
4 |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
5 /* Some platform specifics |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
6 */ |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
7 #if defined(_WIN32) || defined(_WIN64) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
8 # define wcpncpy wcsncpy |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
9 # define wcpcpy wcscpy |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
10 #endif |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
11 |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
12 #ifndef __APPLE__ |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
13 #include <malloc.h> |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
14 #endif |
36 | 15 |
16 | |
37
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
17 /* Sized integer types |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
18 */ |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
19 #ifdef _WIN32 |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
20 #include <wtypes.h> |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
21 typedef unsigned __int8 Uint8; |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
22 typedef unsigned __int16 Uint16; |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
23 typedef unsigned __int32 Uint32; |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
24 typedef unsigned __int64 Uint64; |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
25 #else |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
26 #include <stdint.h> |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
27 typedef uint8_t Uint8; |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
28 typedef uint16_t Uint16; |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
29 typedef uint32_t Uint32; |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
30 typedef uint64_t Uint64; |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
31 #endif |
36 | 32 |
33 | |
34 /* Define a boolean type | |
35 */ | |
36 #if !defined(FALSE) && !defined(TRUE) && !defined(BOOL) | |
37 typedef enum { FALSE = 0, TRUE = 1 } BOOL; | |
38 #endif | |
39 | |
40 #ifndef BOOL | |
41 # ifdef bool | |
42 # define BOOL bool | |
43 # else | |
44 # define BOOL int | |
45 # endif | |
46 #endif | |
47 | |
48 | |
37
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
49 /* Endianess swapping macros |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
50 */ |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
51 #define DM_SWAP_16_LE_BE(value) ((Uint16) ( \ |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
52 (Uint16) ((Uint16) (value) >> 8) | \ |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
53 (Uint16) ((Uint16) (value) << 8)) ) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
54 |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
55 |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
56 #define DM_SWAP_32_LE_BE(value) ((Uint32) ( \ |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
57 (((Uint32) (value) & (Uint32) 0x000000ffU) << 24) | \ |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
58 (((Uint32) (value) & (Uint32) 0x0000ff00U) << 8) | \ |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
59 (((Uint32) (value) & (Uint32) 0x00ff0000U) >> 8) | \ |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
60 (((Uint32) (value) & (Uint32) 0xff000000U) >> 24))) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
61 |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
62 |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
63 /* Macros that swap only when needed ... |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
64 */ |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
65 #if (BYTEORDER == BIG_ENDIAN) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
66 # define DM_LE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
67 # define DM_LE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
68 # define DM_NATIVE_TO_LE16(value) DM_SWAP_16_LE_BE(value) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
69 # define DM_NATIVE_TO_LE32(value) DM_SWAP_32_LE_BE(value) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
70 |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
71 # define DM_BE16_TO_NATIVE(value) ((Uint16) (value)) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
72 # define DM_BE32_TO_NATIVE(value) ((Uint32) (value)) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
73 # define DM_NATIVE_TO_BE16(value) ((Uint16) (value)) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
74 # define DM_NATIVE_TO_BE32(value) ((Uint32) (value)) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
75 |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
76 #elif (BYTEORDER == LIL_ENDIAN) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
77 |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
78 # define DM_LE16_TO_NATIVE(value) ((Uint16) (value)) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
79 # define DM_LE32_TO_NATIVE(value) ((Uint32) (value)) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
80 # define DM_NATIVE_TO_LE16(value) ((Uint16) (value)) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
81 # define DM_NATIVE_TO_LE32(value) ((Uint32) (value)) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
82 |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
83 # define DM_BE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
84 # define DM_BE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
85 # define DM_NATIVE_TO_BE16(value) DM_SWAP_16_LE_BE(value) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
86 # define DM_NATIVE_TO_BE32(value) DM_SWAP_32_LE_BE(value) |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
87 |
36 | 88 #endif |
37
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
89 |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
90 |
1db62040204e
Combine some headers to single mplatform.h
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
91 #endif // MPLATFORM_H |