TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CascPort.h
Go to the documentation of this file.
1 /*****************************************************************************/
2 /* CascPort.h Copyright (c) Ladislav Zezula 2014 */
3 /*---------------------------------------------------------------------------*/
4 /* Portability module for the CascLib library. Contains a wrapper symbols */
5 /* to make the compilation under Linux work */
6 /*---------------------------------------------------------------------------*/
7 /* Date Ver Who Comment */
8 /* -------- ---- --- ------- */
9 /* 29.04.14 1.00 Lad Created */
10 /*****************************************************************************/
11 
12 #ifndef __CASCPORT_H__
13 #define __CASCPORT_H__
14 
15 #ifndef __cplusplus
16  #define bool char
17  #define true 1
18  #define false 0
19 #endif
20 
21 //-----------------------------------------------------------------------------
22 // Defines for Windows
23 
24 #if !defined(PLATFORM_DEFINED) && (defined(WIN32) || defined(WIN64))
25 
26  // In MSVC 8.0, there are some functions declared as deprecated.
27  #if _MSC_VER >= 1400
28  #define _CRT_SECURE_NO_DEPRECATE
29  #define _CRT_NON_CONFORMING_SWPRINTFS
30  #endif
31 
32  #include <tchar.h>
33  #include <assert.h>
34  #include <ctype.h>
35  #include <stdio.h>
36  #include <windows.h>
37  #include <wininet.h>
38  #include <sys/types.h>
39  #define PLATFORM_LITTLE_ENDIAN
40 
41  #ifdef WIN64
42  #define PLATFORM_64BIT
43  #else
44  #define PLATFORM_32BIT
45  #endif
46 
47  #define PATH_SEPARATOR '\\'
48  #define CREATE_DIRECTORY(name) CreateDirectory(name, NULL);
49 
50  #define PLATFORM_WINDOWS
51  #define PLATFORM_DEFINED // The platform is known now
52 
53 #endif
54 
55 //-----------------------------------------------------------------------------
56 // Defines for Mac
57 
58 #if !defined(PLATFORM_DEFINED) && defined(__APPLE__) // Mac BSD API
59 
60  // Macintosh
61  #include <sys/types.h>
62  #include <sys/stat.h>
63  #include <sys/mman.h>
64  #include <unistd.h>
65  #include <fcntl.h>
66  #include <stdlib.h>
67  #include <dirent.h>
68  #include <errno.h>
69  #include <stddef.h>
70 
71  // Support for PowerPC on Max OS X
72  #if (__ppc__ == 1) || (__POWERPC__ == 1) || (_ARCH_PPC == 1)
73  #include <stdint.h>
74  #include <CoreFoundation/CFByteOrder.h>
75  #endif
76 
77  #define PKEXPORT
78  #define __SYS_ZLIB
79  #define __SYS_BZLIB
80 
81  #ifndef __BIG_ENDIAN__
82  #define PLATFORM_LITTLE_ENDIAN
83  #endif
84 
85  #define PATH_SEPARATOR '/'
86  #define CREATE_DIRECTORY(name) mkdir(name, 0755)
87 
88  #define PLATFORM_MAC
89  #define PLATFORM_DEFINED // The platform is known now
90 
91  #define FIELD_OFFSET(t,f) offsetof(t,f)
92 #endif
93 
94 //-----------------------------------------------------------------------------
95 // Assumption: we are not on Windows nor Macintosh, so this must be linux *grin*
96 
97 #if !defined(PLATFORM_DEFINED)
98 
99  #include <sys/types.h>
100  #include <sys/stat.h>
101  #include <sys/mman.h>
102  #include <fcntl.h>
103  #include <dirent.h>
104  #include <unistd.h>
105  #include <stddef.h>
106  #include <stdint.h>
107  #include <stdlib.h>
108  #include <stdio.h>
109  #include <stdarg.h>
110  #include <string.h>
111  #include <ctype.h>
112  #include <assert.h>
113  #include <errno.h>
114 
115  #define PATH_SEPARATOR '/'
116  #define CREATE_DIRECTORY(name) mkdir(name, 0755)
117 
118  #define PLATFORM_LITTLE_ENDIAN
119  #define PLATFORM_LINUX
120  #define PLATFORM_DEFINED
121 
122  #define FIELD_OFFSET(t,f) offsetof(t,f)
123 #endif
124 
125 //-----------------------------------------------------------------------------
126 // Definition of Windows-specific types for non-Windows platforms
127 
128 #ifndef PLATFORM_WINDOWS
129  #if __LP64__
130  #define PLATFORM_64BIT
131  #else
132  #define PLATFORM_32BIT
133  #endif
134 
135  // Typedefs for ANSI C
136  typedef unsigned char BYTE;
137  typedef unsigned short USHORT;
138  typedef int LONG;
139  typedef unsigned int DWORD;
140  typedef unsigned long DWORD_PTR;
141  typedef long LONG_PTR;
142  typedef long INT_PTR;
143  typedef long long LONGLONG;
144  typedef unsigned long long ULONGLONG;
145  typedef unsigned long long *PULONGLONG;
146  typedef void * HANDLE;
147  typedef void * LPOVERLAPPED; // Unsupported on Linux and Mac
148  typedef char TCHAR;
149  typedef unsigned int LCID;
150  typedef LONG * PLONG;
151  typedef DWORD * PDWORD;
152  typedef BYTE * LPBYTE;
153 
154  #ifdef PLATFORM_32BIT
155  #define _LZMA_UINT32_IS_ULONG
156  #endif
157 
158  // Some Windows-specific defines
159  #ifndef MAX_PATH
160  #define MAX_PATH 1024
161  #endif
162 
163  #define WINAPI
164 
165  #define FILE_BEGIN SEEK_SET
166  #define FILE_CURRENT SEEK_CUR
167  #define FILE_END SEEK_END
168 
169  #define INVALID_HANDLE_VALUE ((HANDLE)-1)
170 
171  #define _T(x) x
172  #define _tcslen strlen
173  #define _tcscpy strcpy
174  #define _tcscat strcat
175  #define _tcschr strchr
176  #define _tcsrchr strrchr
177  #define _tcsstr strstr
178  #define _tcsspn strspn
179  #define _tcsncmp strncmp
180  #define _tprintf printf
181  #define _stprintf sprintf
182  #define _tremove remove
183  #define _tmkdir mkdir
184 
185  #define _stricmp strcasecmp
186  #define _strnicmp strncasecmp
187  #define _tcsicmp strcasecmp
188  #define _tcsnicmp strncasecmp
189 
190 #endif // !PLATFORM_WINDOWS
191 
192 // 64-bit calls are supplied by "normal" calls on Mac
193 #if defined(PLATFORM_MAC)
194  #define stat64 stat
195  #define fstat64 fstat
196  #define lseek64 lseek
197  #define ftruncate64 ftruncate
198  #define off64_t off_t
199  #define O_LARGEFILE 0
200 #endif
201 
202 // Platform-specific error codes for UNIX-based platforms
203 #if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX)
204  #define ERROR_SUCCESS 0
205  #define ERROR_FILE_NOT_FOUND ENOENT
206  #define ERROR_ACCESS_DENIED EPERM
207  #define ERROR_INVALID_HANDLE EBADF
208  #define ERROR_NOT_ENOUGH_MEMORY ENOMEM
209  #define ERROR_NOT_SUPPORTED ENOTSUP
210  #define ERROR_INVALID_PARAMETER EINVAL
211  #define ERROR_DISK_FULL ENOSPC
212  #define ERROR_ALREADY_EXISTS EEXIST
213  #define ERROR_INSUFFICIENT_BUFFER ENOBUFS
214  #define ERROR_BAD_FORMAT 1000 // No such error code under Linux
215  #define ERROR_NO_MORE_FILES 1001 // No such error code under Linux
216  #define ERROR_HANDLE_EOF 1002 // No such error code under Linux
217  #define ERROR_CAN_NOT_COMPLETE 1003 // No such error code under Linux
218  #define ERROR_FILE_CORRUPT 1004 // No such error code under Linux
219 #endif
220 
221 //-----------------------------------------------------------------------------
222 // Swapping functions
223 
224 #ifdef PLATFORM_LITTLE_ENDIAN
225  #define BSWAP_INT16_UNSIGNED(a) (a)
226  #define BSWAP_INT16_SIGNED(a) (a)
227  #define BSWAP_INT32_UNSIGNED(a) (a)
228  #define BSWAP_INT32_SIGNED(a) (a)
229  #define BSWAP_INT64_SIGNED(a) (a)
230  #define BSWAP_INT64_UNSIGNED(a) (a)
231  #define BSWAP_ARRAY16_UNSIGNED(a,b) {}
232  #define BSWAP_ARRAY32_UNSIGNED(a,b) {}
233  #define BSWAP_ARRAY64_UNSIGNED(a,b) {}
234 #else
235 
236 #ifdef __cplusplus
237  extern "C" {
238 #endif
239  int16_t SwapInt16(uint16_t);
240  uint16_t SwapUInt16(uint16_t);
241  int32_t SwapInt32(uint32_t);
242  uint32_t SwapUInt32(uint32_t);
243  int64_t SwapInt64(uint64_t);
244  uint64_t SwapUInt64(uint64_t);
245  void ConvertUInt16Buffer(void * ptr, size_t length);
246  void ConvertUInt32Buffer(void * ptr, size_t length);
247  void ConvertUInt64Buffer(void * ptr, size_t length);
248 #ifdef __cplusplus
249  }
250 #endif
251  #define BSWAP_INT16_SIGNED(a) SwapInt16((a))
252  #define BSWAP_INT16_UNSIGNED(a) SwapUInt16((a))
253  #define BSWAP_INT32_SIGNED(a) SwapInt32((a))
254  #define BSWAP_INT32_UNSIGNED(a) SwapUInt32((a))
255  #define BSWAP_INT64_SIGNED(a) SwapInt64((a))
256  #define BSWAP_INT64_UNSIGNED(a) SwapUInt64((a))
257  #define BSWAP_ARRAY16_UNSIGNED(a,b) ConvertUInt16Buffer((a),(b))
258  #define BSWAP_ARRAY32_UNSIGNED(a,b) ConvertUInt32Buffer((a),(b))
259  #define BSWAP_ARRAY64_UNSIGNED(a,b) ConvertUInt64Buffer((a),(b))
260 #endif
261 
262 #endif // __CASCPORT_H__
void * HANDLE
Definition: CascPort.h:146
unsigned long long ULONGLONG
Definition: CascPort.h:144
DWORD * PDWORD
Definition: CascPort.h:151
signed short int16_t
Definition: stdint.h:76
void * LPOVERLAPPED
Definition: CascPort.h:147
char TCHAR
Definition: CascPort.h:148
int LONG
Definition: CascPort.h:138
signed __int64 int64_t
Definition: stdint.h:89
BYTE * LPBYTE
Definition: CascPort.h:152
LONG * PLONG
Definition: CascPort.h:150
unsigned short USHORT
Definition: CascPort.h:137
unsigned int uint32_t
Definition: stdint.h:80
unsigned long long * PULONGLONG
Definition: CascPort.h:145
unsigned __int64 uint64_t
Definition: stdint.h:90
unsigned long DWORD_PTR
Definition: CascPort.h:140
unsigned int LCID
Definition: CascPort.h:149
long LONG_PTR
Definition: CascPort.h:141
unsigned int DWORD
Definition: CascPort.h:139
float length(float v)
Definition: vectorMath.h:208
long long LONGLONG
Definition: CascPort.h:143
signed int int32_t
Definition: stdint.h:77
unsigned char BYTE
Definition: CascPort.h:136
unsigned short uint16_t
Definition: stdint.h:79
long INT_PTR
Definition: CascPort.h:142