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 */
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 */
12 /* Author: Sam Wilkins */
13 /* System: Mac OS X and port to big endian processor */
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 /*****************************************************************************/
26 #ifndef __STORMPORT_H__
27 #define __STORMPORT_H__
29 // Defines for Windows
30 #if !defined(PLATFORM_DEFINED) && (defined(WIN32) || defined(WIN64))
32 // In MSVC 8.0, there are some functions declared as deprecated.
34 #define _CRT_SECURE_NO_DEPRECATE
35 #define _CRT_NON_CONFORMING_SWPRINTFS
41 #define PLATFORM_LITTLE_ENDIAN 1
44 #define PLATFORM_64BIT
46 #define PLATFORM_32BIT
49 #define PLATFORM_DEFINED // The platform is known now
53 // Defines for Mac Carbon
54 #if !defined(PLATFORM_DEFINED) && defined(__APPLE__) // Mac Carbon API
56 // Macintosh using Carbon
57 #include <Carbon/Carbon.h> // Mac OS X
58 #define _stricmp strcasecmp // Case insensitive strcmp has a different name on this platform.
59 #define _strnicmp strncasecmp
61 typedef void * LPCSTR
;
62 typedef unsigned long * LPDWORD
;
64 typedef void * LPVOID
;
65 typedef unsigned int UINT
;
70 #define LANG_NEUTRAL 0
72 #if defined(__BIG_ENDIAN__)
73 #define PLATFORM_LITTLE_ENDIAN 0
75 #define PLATFORM_LITTLE_ENDIAN 1 // Apple is now making Macs with Intel CPUs
77 #define PLATFORM_DEFINED // The platform is known now
81 // Assumption: we are not on Windows nor Macintosh, so this must be linux *grin*
82 // Ladik : Why the hell Linux does not use some OS-dependent #define ?
83 #if !defined(PLATFORM_DEFINED)
85 #include <sys/types.h>
97 #define PLATFORM_LITTLE_ENDIAN 1
98 #define PLATFORM_DEFINED
99 #define LANG_NEUTRAL 0
101 #endif /* not __powerc */
104 #if !defined(WIN32) && !defined(WIN64)
106 // Typedefs for ANSI C
107 typedef unsigned char BYTE
;
109 typedef unsigned short WORD
;
110 typedef unsigned short USHORT
;
112 typedef unsigned long DWORD
;
113 typedef unsigned long DWORD_PTR
;
114 typedef long LONG_PTR
;
115 typedef long long LONGLONG
;
119 typedef void * HANDLE
;
120 typedef void * LPOVERLAPPED
; // Unsupported on Linux
122 typedef unsigned long LCID
;
124 typedef void * LPCSTR
;
125 typedef unsigned long * LPDWORD
;
126 typedef long * PLONG
;
127 typedef void * LPVOID
;
128 typedef unsigned int UINT
;
130 typedef struct _FILETIME
133 DWORD dwHighDateTime
;
135 FILETIME
, *PFILETIME
;
137 typedef union _LARGE_INTEGER
139 #if PLATFORM_LITTLE_ENDIAN
154 LARGE_INTEGER
, *PLARGE_INTEGER
;
156 // Some Windows-specific defines
158 #define MAX_PATH 1024
172 #define FILE_BEGIN SEEK_SET
173 #define FILE_CURRENT SEEK_CUR
174 #define FILE_END SEEK_END
177 #define CREATE_ALWAYS 2
178 #define OPEN_EXISTING 3
179 #define OPEN_ALWAYS 4
181 #define FILE_SHARE_READ 0x00000001L
182 #define GENERIC_WRITE 0x40000000
183 #define GENERIC_READ 0x80000000
185 #define FILE_FLAG_DELETE_ON_CLOSE 1 // Sam: Added these two defines so it would compile.
186 #define FILE_FLAG_SEQUENTIAL_SCAN 2
188 #define ERROR_SUCCESS 0
189 #define ERROR_INVALID_FUNCTION 1
190 #define ERROR_FILE_NOT_FOUND 2
191 #define ERROR_ACCESS_DENIED 5
192 #define ERROR_NOT_ENOUGH_MEMORY 8
193 #define ERROR_BAD_FORMAT 11
194 #define ERROR_NO_MORE_FILES 18
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
208 #define INVALID_HANDLE_VALUE ((HANDLE) -1)
211 #define min(a, b) ((a < b) ? a : b)
215 #define max(a, b) ((a > b) ? a : b)
218 #define _stricmp strcasecmp
219 #define _strnicmp strncasecmp
221 extern int globalerr
;
223 void SetLastError(int err
);
225 char *ErrString(int err
);
227 // Emulation of functions for file I/O available in Win32
228 HANDLE
CreateFile(const char * lpFileName
, DWORD dwDesiredAccess
, DWORD dwShareMode
, void * lpSecurityAttributes
, DWORD dwCreationDisposition
, DWORD dwFlagsAndAttributes
, HANDLE hTemplateFile
);
229 BOOL
CloseHandle(HANDLE hObject
);
231 DWORD
GetFileSize(HANDLE hFile
, DWORD
* lpFileSizeHigh
);
232 DWORD
SetFilePointer(HANDLE
, LONG lDistanceToMove
, LONG
* lpDistanceToMoveHigh
, DWORD dwMoveMethod
);
233 BOOL
SetEndOfFile(HANDLE hFile
);
235 BOOL
ReadFile(HANDLE hFile
, void * lpBuffer
, DWORD nNumberOfBytesToRead
, DWORD
* lpNumberOfBytesRead
, void * lpOverLapped
);
236 BOOL
WriteFile(HANDLE hFile
, const void * lpBuffer
, DWORD nNumberOfBytesToWrite
, DWORD
* lpNumberOfBytesWritten
, void * lpOverLapped
);
238 BOOL
IsBadReadPtr(const void * ptr
, int size
);
239 DWORD
GetFileAttributes(const char * szileName
);
241 BOOL
DeleteFile(const char * lpFileName
);
242 BOOL
MoveFile(const char * lpFromFileName
, const char * lpToFileName
);
243 void GetTempPath(DWORD szTempLength
, char * szTemp
);
244 void GetTempFileName(const char * lpTempFolderPath
, const char * lpFileName
, DWORD something
, char * szLFName
);
246 #define strnicmp strncasecmp
250 #if PLATFORM_LITTLE_ENDIAN
251 #define BSWAP_INT16_UNSIGNED(a) (a)
252 #define BSWAP_INT16_SIGNED(a) (a)
253 #define BSWAP_INT32_UNSIGNED(a) (a)
254 #define BSWAP_INT32_SIGNED(a) (a)
255 #define BSWAP_ARRAY16_UNSIGNED(a,b) {}
256 #define BSWAP_ARRAY32_UNSIGNED(a,b) {}
257 #define BSWAP_TMPQSHUNT(a) {}
258 #define BSWAP_TMPQHEADER(a) {}
260 extern unsigned short SwapUShort(unsigned short);
261 extern unsigned long SwapULong(unsigned long);
262 extern short SwapShort(unsigned short);
263 extern long SwapLong(unsigned long);
264 extern void ConvertUnsignedLongBuffer(unsigned long *buffer
, unsigned long nbLongs
);
265 extern void ConvertUnsignedShortBuffer(unsigned short *buffer
, unsigned long nbShorts
);
266 extern void ConvertTMPQShunt(void *shunt
);
267 extern void ConvertTMPQHeader(void *header
);
268 #define BSWAP_INT16_UNSIGNED(a) SwapUShort((a))
269 #define BSWAP_INT32_UNSIGNED(a) SwapULong((a))
270 #define BSWAP_INT16_SIGNED(a) SwapShort((a))
271 #define BSWAP_INT32_SIGNED(a) SwapLong((a))
272 #define BSWAP_ARRAY16_UNSIGNED(a,b) ConvertUnsignedShortBuffer((a),(b))
273 #define BSWAP_ARRAY32_UNSIGNED(a,b) ConvertUnsignedLongBuffer((a),(b))
274 #define BSWAP_TMPQSHUNT(a) ConvertTMPQShunt((a))
275 #define BSWAP_TMPQHEADER(a) ConvertTMPQHeader((a))
278 #endif // __STORMPORT_H__