1 | /*****************************************************************************/
|
---|
2 | /* StormPort.h Copyright (c) Marko Friedemann 2001 */
|
---|
3 | /*---------------------------------------------------------------------------*/
|
---|
4 | /* Portability module for the StormLib library. Contains a wrapper symbols */
|
---|
5 | /* to make the compilation under Linux work */
|
---|
6 | /* */
|
---|
7 | /* Author: Marko Friedemann <marko.friedemann@bmx-chemnitz.de> */
|
---|
8 | /* Created at: Mon Jan 29 18:26:01 CEST 2001 */
|
---|
9 | /* Computer: whiplash.flachland-chemnitz.de */
|
---|
10 | /* System: Linux 2.4.0 on i686 */
|
---|
11 | /* */
|
---|
12 | /* Author: Sam Wilkins */
|
---|
13 | /* System: Mac OS X and port to big endian processor */
|
---|
14 | /* */
|
---|
15 | /*---------------------------------------------------------------------------*/
|
---|
16 | /* Date Ver Who Comment */
|
---|
17 | /* -------- ---- --- ------- */
|
---|
18 | /* 29.01.01 1.00 Mar Created */
|
---|
19 | /* 24.03.03 1.01 Lad Some cosmetic changes */
|
---|
20 | /* 12.11.03 1.02 Dan Macintosh compatibility */
|
---|
21 | /* 24.07.04 1.03 Sam Mac OS X compatibility */
|
---|
22 | /* 22.11.06 1.04 Sam Mac OS X compatibility (for StormLib 6.0) */
|
---|
23 | /* 31.12.06 1.05 XPinguin Full GNU/Linux compatibility */
|
---|
24 | /*****************************************************************************/
|
---|
25 |
|
---|
26 | #ifndef __STORMPORT_H__
|
---|
27 | #define __STORMPORT_H__
|
---|
28 |
|
---|
29 | // Defines for Windows
|
---|
30 | #if !defined(PLATFORM_DEFINED) && (defined(WIN32) || defined(WIN64))
|
---|
31 |
|
---|
32 | // In MSVC 8.0, there are some functions declared as deprecated.
|
---|
33 | #if _MSC_VER >= 1400
|
---|
34 | #define _CRT_SECURE_NO_DEPRECATE
|
---|
35 | #define _CRT_NON_CONFORMING_SWPRINTFS
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | #include <assert.h>
|
---|
39 | #include <stdio.h>
|
---|
40 | #include <windows.h>
|
---|
41 | #define PLATFORM_LITTLE_ENDIAN 1
|
---|
42 |
|
---|
43 | #ifdef WIN64
|
---|
44 | #define PLATFORM_64BIT
|
---|
45 | #else
|
---|
46 | #define PLATFORM_32BIT
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | #define PLATFORM_DEFINED // The platform is known now
|
---|
50 |
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | // Defines for Mac Carbon
|
---|
54 | #if !defined(PLATFORM_DEFINED) && defined(__APPLE__) // Mac Carbon API
|
---|
55 |
|
---|
56 | // Macintosh using Carbon
|
---|
57 | #include <Carbon/Carbon.h> // Mac OS X
|
---|
58 |
|
---|
59 | #define PKEXPORT
|
---|
60 | #define __SYS_ZLIB
|
---|
61 | #define __SYS_BZLIB
|
---|
62 | #define LANG_NEUTRAL 0
|
---|
63 |
|
---|
64 | #if defined(__BIG_ENDIAN__)
|
---|
65 | #define PLATFORM_LITTLE_ENDIAN 0
|
---|
66 | #else
|
---|
67 | #define PLATFORM_LITTLE_ENDIAN 1 // Apple is now making Macs with Intel CPUs
|
---|
68 | #endif
|
---|
69 |
|
---|
70 | #ifdef __LP64__
|
---|
71 | #define PLATFORM_64BIT
|
---|
72 | #else
|
---|
73 | #define PLATFORM_32BIT
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | #define PLATFORM_DEFINED // The platform is known now
|
---|
77 |
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | // Assumption: we are not on Windows nor Macintosh, so this must be linux *grin*
|
---|
81 | // Ladik : Why the hell Linux does not use some OS-dependent #define ?
|
---|
82 | #if !defined(PLATFORM_DEFINED)
|
---|
83 |
|
---|
84 | #include <sys/types.h>
|
---|
85 | #include <sys/stat.h>
|
---|
86 | #include <fcntl.h>
|
---|
87 | #include <unistd.h>
|
---|
88 | #include <stdint.h>
|
---|
89 | #include <stdlib.h>
|
---|
90 | #include <stdio.h>
|
---|
91 | #include <stdarg.h>
|
---|
92 | #include <string.h>
|
---|
93 | #include <ctype.h>
|
---|
94 | #include <assert.h>
|
---|
95 |
|
---|
96 | #define PLATFORM_LITTLE_ENDIAN 1
|
---|
97 | #define PLATFORM_DEFINED
|
---|
98 | #define LANG_NEUTRAL 0
|
---|
99 |
|
---|
100 | #endif /* not __powerc */
|
---|
101 |
|
---|
102 |
|
---|
103 | #if !defined(WIN32) && !defined(WIN64)
|
---|
104 |
|
---|
105 | // Typedefs for ANSI C
|
---|
106 | typedef unsigned char BYTE;
|
---|
107 | typedef int16_t SHORT;
|
---|
108 | typedef uint16_t WORD;
|
---|
109 | typedef uint16_t USHORT;
|
---|
110 | typedef int32_t LONG;
|
---|
111 | typedef uint32_t DWORD;
|
---|
112 | typedef intptr_t DWORD_PTR;
|
---|
113 | typedef intptr_t LONG_PTR;
|
---|
114 | typedef intptr_t INT_PTR;
|
---|
115 | typedef int64_t LONGLONG;
|
---|
116 | #ifndef __OBJC__
|
---|
117 | #ifdef __cplusplus
|
---|
118 | #define BOOL bool
|
---|
119 | #else
|
---|
120 | #define BOOL int
|
---|
121 | #endif
|
---|
122 | #endif
|
---|
123 | typedef void * HANDLE;
|
---|
124 | typedef void * LPOVERLAPPED; // Unsupported on Linux and Mac
|
---|
125 | typedef char TCHAR;
|
---|
126 | typedef uint32_t LCID;
|
---|
127 | typedef unsigned int UINT;
|
---|
128 | typedef LONG * PLONG;
|
---|
129 | typedef DWORD * LPDWORD;
|
---|
130 | typedef BYTE * LPBYTE;
|
---|
131 |
|
---|
132 | typedef struct _FILETIME
|
---|
133 | {
|
---|
134 | DWORD dwLowDateTime;
|
---|
135 | DWORD dwHighDateTime;
|
---|
136 | }
|
---|
137 | FILETIME, *PFILETIME;
|
---|
138 |
|
---|
139 | typedef union _LARGE_INTEGER
|
---|
140 | {
|
---|
141 | #if PLATFORM_LITTLE_ENDIAN
|
---|
142 | struct
|
---|
143 | {
|
---|
144 | DWORD LowPart;
|
---|
145 | LONG HighPart;
|
---|
146 | };
|
---|
147 | #else
|
---|
148 | struct
|
---|
149 | {
|
---|
150 | LONG HighPart;
|
---|
151 | DWORD LowPart;
|
---|
152 | };
|
---|
153 | #endif
|
---|
154 | LONGLONG QuadPart;
|
---|
155 | }
|
---|
156 | LARGE_INTEGER, *PLARGE_INTEGER;
|
---|
157 |
|
---|
158 | // Some Windows-specific defines
|
---|
159 | #ifndef MAX_PATH
|
---|
160 | #define MAX_PATH 1024
|
---|
161 | #endif
|
---|
162 |
|
---|
163 | #ifndef TRUE
|
---|
164 | #define TRUE true
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | #ifndef FALSE
|
---|
168 | #define FALSE false
|
---|
169 | #endif
|
---|
170 |
|
---|
171 | #define VOID void
|
---|
172 | #define WINAPI
|
---|
173 |
|
---|
174 | #define FILE_BEGIN SEEK_SET
|
---|
175 | #define FILE_CURRENT SEEK_CUR
|
---|
176 | #define FILE_END SEEK_END
|
---|
177 |
|
---|
178 | #define CREATE_NEW 1
|
---|
179 | #define CREATE_ALWAYS 2
|
---|
180 | #define OPEN_EXISTING 3
|
---|
181 | #define OPEN_ALWAYS 4
|
---|
182 |
|
---|
183 | #define FILE_SHARE_READ 0x00000001L
|
---|
184 | #define GENERIC_WRITE 0x40000000
|
---|
185 | #define GENERIC_READ 0x80000000
|
---|
186 |
|
---|
187 | #define ERROR_SUCCESS 0
|
---|
188 | #define ERROR_INVALID_FUNCTION 1
|
---|
189 | #define ERROR_FILE_NOT_FOUND 2
|
---|
190 | #define ERROR_ACCESS_DENIED 5
|
---|
191 | #define ERROR_NOT_ENOUGH_MEMORY 8
|
---|
192 | #define ERROR_BAD_FORMAT 11
|
---|
193 | #define ERROR_NO_MORE_FILES 18
|
---|
194 | #define ERROR_WRITE_FAULT 29
|
---|
195 | #define ERROR_GEN_FAILURE 31
|
---|
196 | #define ERROR_HANDLE_EOF 38
|
---|
197 | #define ERROR_HANDLE_DISK_FULL 39
|
---|
198 | #define ERROR_NOT_SUPPORTED 50
|
---|
199 | #define ERROR_INVALID_PARAMETER 87
|
---|
200 | #define ERROR_DISK_FULL 112
|
---|
201 | #define ERROR_CALL_NOT_IMPLEMENTED 120
|
---|
202 | #define ERROR_ALREADY_EXISTS 183
|
---|
203 | #define ERROR_CAN_NOT_COMPLETE 1003
|
---|
204 | #define ERROR_PARAMETER_QUOTA_EXCEEDED 1283
|
---|
205 | #define ERROR_FILE_CORRUPT 1392
|
---|
206 | #define ERROR_INSUFFICIENT_BUFFER 4999
|
---|
207 |
|
---|
208 | #define INVALID_HANDLE_VALUE ((HANDLE) -1)
|
---|
209 |
|
---|
210 | #define _stricmp strcasecmp
|
---|
211 | #define _strnicmp strncasecmp
|
---|
212 |
|
---|
213 | extern int globalerr;
|
---|
214 |
|
---|
215 | void SetLastError(int err);
|
---|
216 | int GetLastError();
|
---|
217 | char *ErrString(int err);
|
---|
218 |
|
---|
219 | // Emulation of functions for file I/O available in Win32
|
---|
220 | HANDLE CreateFile(const char * lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, void * lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
|
---|
221 | BOOL CloseHandle(HANDLE hObject);
|
---|
222 |
|
---|
223 | DWORD GetFileSize(HANDLE hFile, DWORD * lpFileSizeHigh);
|
---|
224 | DWORD SetFilePointer(HANDLE, LONG lDistanceToMove, LONG * lpDistanceToMoveHigh, DWORD dwMoveMethod);
|
---|
225 | BOOL SetEndOfFile(HANDLE hFile);
|
---|
226 |
|
---|
227 | BOOL ReadFile(HANDLE hFile, void * lpBuffer, DWORD nNumberOfBytesToRead, DWORD * lpNumberOfBytesRead, void * lpOverLapped);
|
---|
228 | BOOL WriteFile(HANDLE hFile, const void * lpBuffer, DWORD nNumberOfBytesToWrite, DWORD * lpNumberOfBytesWritten, void * lpOverLapped);
|
---|
229 |
|
---|
230 | BOOL IsBadReadPtr(const void * ptr, int size);
|
---|
231 | DWORD GetFileAttributes(const char * szileName);
|
---|
232 |
|
---|
233 | BOOL DeleteFile(const char * lpFileName);
|
---|
234 | BOOL MoveFile(const char * lpFromFileName, const char * lpToFileName);
|
---|
235 | void GetTempPath(DWORD szTempLength, char * szTemp);
|
---|
236 | void GetTempFileName(const char * lpTempFolderPath, const char * lpFileName, DWORD something, char * szLFName);
|
---|
237 |
|
---|
238 | #define strnicmp strncasecmp
|
---|
239 |
|
---|
240 | #endif // !WIN32
|
---|
241 |
|
---|
242 | #if PLATFORM_LITTLE_ENDIAN
|
---|
243 | #define BSWAP_INT16_UNSIGNED(a) (a)
|
---|
244 | #define BSWAP_INT16_SIGNED(a) (a)
|
---|
245 | #define BSWAP_INT32_UNSIGNED(a) (a)
|
---|
246 | #define BSWAP_INT32_SIGNED(a) (a)
|
---|
247 | #define BSWAP_ARRAY16_UNSIGNED(a,b) {}
|
---|
248 | #define BSWAP_ARRAY32_UNSIGNED(a,b) {}
|
---|
249 | #define BSWAP_TMPQSHUNT(a) {}
|
---|
250 | #define BSWAP_TMPQHEADER(a) {}
|
---|
251 | #else
|
---|
252 | extern uint16_t SwapUShort(uint16_t);
|
---|
253 | extern uint32_t SwapULong(uint32_t);
|
---|
254 | extern int16_t SwapShort(uint16_t);
|
---|
255 | extern int32_t SwapLong(uint32_t);
|
---|
256 | extern void ConvertUnsignedLongBuffer(uint32_t *buffer, uint32_t nbLongs);
|
---|
257 | extern void ConvertUnsignedShortBuffer(uint16_t *buffer, uint32_t nbShorts);
|
---|
258 | extern void ConvertTMPQShunt(void *shunt);
|
---|
259 | extern void ConvertTMPQHeader(void *header);
|
---|
260 | #define BSWAP_INT16_UNSIGNED(a) SwapUShort((a))
|
---|
261 | #define BSWAP_INT32_UNSIGNED(a) SwapULong((a))
|
---|
262 | #define BSWAP_INT16_SIGNED(a) SwapShort((a))
|
---|
263 | #define BSWAP_INT32_SIGNED(a) SwapLong((a))
|
---|
264 | #define BSWAP_ARRAY16_UNSIGNED(a,b) ConvertUnsignedShortBuffer((a),(b))
|
---|
265 | #define BSWAP_ARRAY32_UNSIGNED(a,b) ConvertUnsignedLongBuffer((a),(b))
|
---|
266 | #define BSWAP_TMPQSHUNT(a) ConvertTMPQShunt((a))
|
---|
267 | #define BSWAP_TMPQHEADER(a) ConvertTMPQHeader((a))
|
---|
268 | #endif
|
---|
269 |
|
---|
270 | #endif // __STORMPORT_H__
|
---|