Mercurial > hg > forks > bilotrip-mj12
comparison 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 |
comparison
equal
deleted
inserted
replaced
36:bef14a3387a1 | 37:1db62040204e |
---|---|
1 #ifndef MPLATFORM_H | |
2 #define MPLATFORM_H 1 | |
3 | |
4 | |
5 /* Some platform specifics | |
6 */ | |
7 #if defined(_WIN32) || defined(_WIN64) | |
8 # define wcpncpy wcsncpy | |
9 # define wcpcpy wcscpy | |
10 #endif | |
11 | |
12 #ifndef __APPLE__ | |
13 #include <malloc.h> | |
14 #endif | |
15 | |
16 | |
17 /* Sized integer types | |
18 */ | |
19 #ifdef _WIN32 | |
20 #include <wtypes.h> | |
21 typedef unsigned __int8 Uint8; | |
22 typedef unsigned __int16 Uint16; | |
23 typedef unsigned __int32 Uint32; | |
24 typedef unsigned __int64 Uint64; | |
25 #else | |
26 #include <stdint.h> | |
27 typedef uint8_t Uint8; | |
28 typedef uint16_t Uint16; | |
29 typedef uint32_t Uint32; | |
30 typedef uint64_t Uint64; | |
31 #endif | |
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 | |
49 /* Endianess swapping macros | |
50 */ | |
51 #define DM_SWAP_16_LE_BE(value) ((Uint16) ( \ | |
52 (Uint16) ((Uint16) (value) >> 8) | \ | |
53 (Uint16) ((Uint16) (value) << 8)) ) | |
54 | |
55 | |
56 #define DM_SWAP_32_LE_BE(value) ((Uint32) ( \ | |
57 (((Uint32) (value) & (Uint32) 0x000000ffU) << 24) | \ | |
58 (((Uint32) (value) & (Uint32) 0x0000ff00U) << 8) | \ | |
59 (((Uint32) (value) & (Uint32) 0x00ff0000U) >> 8) | \ | |
60 (((Uint32) (value) & (Uint32) 0xff000000U) >> 24))) | |
61 | |
62 | |
63 /* Macros that swap only when needed ... | |
64 */ | |
65 #if (BYTEORDER == BIG_ENDIAN) | |
66 # define DM_LE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value) | |
67 # define DM_LE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value) | |
68 # define DM_NATIVE_TO_LE16(value) DM_SWAP_16_LE_BE(value) | |
69 # define DM_NATIVE_TO_LE32(value) DM_SWAP_32_LE_BE(value) | |
70 | |
71 # define DM_BE16_TO_NATIVE(value) ((Uint16) (value)) | |
72 # define DM_BE32_TO_NATIVE(value) ((Uint32) (value)) | |
73 # define DM_NATIVE_TO_BE16(value) ((Uint16) (value)) | |
74 # define DM_NATIVE_TO_BE32(value) ((Uint32) (value)) | |
75 | |
76 #elif (BYTEORDER == LIL_ENDIAN) | |
77 | |
78 # define DM_LE16_TO_NATIVE(value) ((Uint16) (value)) | |
79 # define DM_LE32_TO_NATIVE(value) ((Uint32) (value)) | |
80 # define DM_NATIVE_TO_LE16(value) ((Uint16) (value)) | |
81 # define DM_NATIVE_TO_LE32(value) ((Uint32) (value)) | |
82 | |
83 # define DM_BE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value) | |
84 # define DM_BE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value) | |
85 # define DM_NATIVE_TO_BE16(value) DM_SWAP_16_LE_BE(value) | |
86 # define DM_NATIVE_TO_BE32(value) DM_SWAP_32_LE_BE(value) | |
87 | |
88 #endif | |
89 | |
90 | |
91 #endif // MPLATFORM_H |