| 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 <swilkins1337@gmail.com> */
|
|---|
| 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 | /* 17.10.12 1.05 Lad Moved error codes so they don't overlap with errno.h */
|
|---|
| 25 | /*****************************************************************************/
|
|---|
| 26 |
|
|---|
| 27 | #ifndef __STORMPORT_H__
|
|---|
| 28 | #define __STORMPORT_H__
|
|---|
| 29 |
|
|---|
| 30 | #ifndef __cplusplus
|
|---|
| 31 | #define bool char
|
|---|
| 32 | #define true 1
|
|---|
| 33 | #define false 0
|
|---|
| 34 | #endif
|
|---|
| 35 |
|
|---|
| 36 | // Defines for Windows
|
|---|
| 37 | #if !defined(PLATFORM_DEFINED) && (defined(WIN32) || defined(WIN64))
|
|---|
| 38 |
|
|---|
| 39 | // In MSVC 8.0, there are some functions declared as deprecated.
|
|---|
| 40 | #if _MSC_VER >= 1400
|
|---|
| 41 | #define _CRT_SECURE_NO_DEPRECATE
|
|---|
| 42 | #define _CRT_NON_CONFORMING_SWPRINTFS
|
|---|
| 43 | #endif
|
|---|
| 44 |
|
|---|
| 45 | #include <tchar.h>
|
|---|
| 46 | #include <assert.h>
|
|---|
| 47 | #include <ctype.h>
|
|---|
| 48 | #include <stdio.h>
|
|---|
| 49 | #include <windows.h>
|
|---|
| 50 | #include <wininet.h>
|
|---|
| 51 | #define PLATFORM_LITTLE_ENDIAN
|
|---|
| 52 |
|
|---|
| 53 | #ifdef WIN64
|
|---|
| 54 | #define PLATFORM_64BIT
|
|---|
| 55 | #else
|
|---|
| 56 | #define PLATFORM_32BIT
|
|---|
| 57 | #endif
|
|---|
| 58 |
|
|---|
| 59 | #define PLATFORM_WINDOWS
|
|---|
| 60 | #define PLATFORM_DEFINED // The platform is known now
|
|---|
| 61 |
|
|---|
| 62 | #endif
|
|---|
| 63 |
|
|---|
| 64 | // Defines for Mac
|
|---|
| 65 | #if !defined(PLATFORM_DEFINED) && defined(__APPLE__) // Mac BSD API
|
|---|
| 66 |
|
|---|
| 67 | // Macintosh
|
|---|
| 68 | #include <sys/types.h>
|
|---|
| 69 | #include <sys/stat.h>
|
|---|
| 70 | #include <sys/mman.h>
|
|---|
| 71 | #include <unistd.h>
|
|---|
| 72 | #include <fcntl.h>
|
|---|
| 73 | #include <stdlib.h>
|
|---|
| 74 | #include <errno.h>
|
|---|
| 75 |
|
|---|
| 76 | // Support for PowerPC on Max OS X
|
|---|
| 77 | #if (__ppc__ == 1) || (__POWERPC__ == 1) || (_ARCH_PPC == 1)
|
|---|
| 78 | #include <stdint.h>
|
|---|
| 79 | #include <CoreFoundation/CFByteOrder.h>
|
|---|
| 80 | #endif
|
|---|
| 81 |
|
|---|
| 82 | #define PKEXPORT
|
|---|
| 83 | #define __SYS_ZLIB
|
|---|
| 84 | #define __SYS_BZLIB
|
|---|
| 85 |
|
|---|
| 86 | #ifndef __BIG_ENDIAN__
|
|---|
| 87 | #define PLATFORM_LITTLE_ENDIAN
|
|---|
| 88 | #endif
|
|---|
| 89 |
|
|---|
| 90 | #define PLATFORM_MAC
|
|---|
| 91 | #define PLATFORM_DEFINED // The platform is known now
|
|---|
| 92 |
|
|---|
| 93 | #endif
|
|---|
| 94 |
|
|---|
| 95 | // Assumption: we are not on Windows nor Macintosh, so this must be linux *grin*
|
|---|
| 96 | #if !defined(PLATFORM_DEFINED)
|
|---|
| 97 |
|
|---|
| 98 | #include <sys/types.h>
|
|---|
| 99 | #include <sys/stat.h>
|
|---|
| 100 | #include <sys/mman.h>
|
|---|
| 101 | #include <fcntl.h>
|
|---|
| 102 | #include <unistd.h>
|
|---|
| 103 | #include <stdint.h>
|
|---|
| 104 | #include <stdlib.h>
|
|---|
| 105 | #include <stdio.h>
|
|---|
| 106 | #include <stdarg.h>
|
|---|
| 107 | #include <string.h>
|
|---|
| 108 | #include <ctype.h>
|
|---|
| 109 | #include <assert.h>
|
|---|
| 110 | #include <errno.h>
|
|---|
| 111 |
|
|---|
| 112 | #define PLATFORM_LITTLE_ENDIAN
|
|---|
| 113 | #define PLATFORM_LINUX
|
|---|
| 114 | #define PLATFORM_DEFINED
|
|---|
| 115 |
|
|---|
| 116 | #endif
|
|---|
| 117 |
|
|---|
| 118 | // Definition of Windows-specific structures for non-Windows platforms
|
|---|
| 119 | #ifndef PLATFORM_WINDOWS
|
|---|
| 120 | #if __LP64__
|
|---|
| 121 | #define PLATFORM_64BIT
|
|---|
| 122 | #else
|
|---|
| 123 | #define PLATFORM_32BIT
|
|---|
| 124 | #endif
|
|---|
| 125 |
|
|---|
| 126 | // Typedefs for ANSI C
|
|---|
| 127 | typedef unsigned char BYTE;
|
|---|
| 128 | typedef unsigned short USHORT;
|
|---|
| 129 | typedef int LONG;
|
|---|
| 130 | typedef unsigned int DWORD;
|
|---|
| 131 | typedef unsigned long DWORD_PTR;
|
|---|
| 132 | typedef long LONG_PTR;
|
|---|
| 133 | typedef long INT_PTR;
|
|---|
| 134 | typedef long long LONGLONG;
|
|---|
| 135 | typedef unsigned long long ULONGLONG;
|
|---|
| 136 | typedef void * HANDLE;
|
|---|
| 137 | typedef void * LPOVERLAPPED; // Unsupported on Linux and Mac
|
|---|
| 138 | typedef char TCHAR;
|
|---|
| 139 | typedef unsigned int LCID;
|
|---|
| 140 | typedef LONG * PLONG;
|
|---|
| 141 | typedef DWORD * LPDWORD;
|
|---|
| 142 | typedef BYTE * LPBYTE;
|
|---|
| 143 |
|
|---|
| 144 | #ifdef PLATFORM_32BIT
|
|---|
| 145 | #define _LZMA_UINT32_IS_ULONG
|
|---|
| 146 | #endif
|
|---|
| 147 |
|
|---|
| 148 | // Some Windows-specific defines
|
|---|
| 149 | #ifndef MAX_PATH
|
|---|
| 150 | #define MAX_PATH 1024
|
|---|
| 151 | #endif
|
|---|
| 152 |
|
|---|
| 153 | #define WINAPI
|
|---|
| 154 |
|
|---|
| 155 | #define FILE_BEGIN SEEK_SET
|
|---|
| 156 | #define FILE_CURRENT SEEK_CUR
|
|---|
| 157 | #define FILE_END SEEK_END
|
|---|
| 158 |
|
|---|
| 159 | #define _T(x) x
|
|---|
| 160 | #define _tcslen strlen
|
|---|
| 161 | #define _tcscpy strcpy
|
|---|
| 162 | #define _tcscat strcat
|
|---|
| 163 | #define _tcsrchr strrchr
|
|---|
| 164 | #define _tprintf printf
|
|---|
| 165 | #define _stprintf sprintf
|
|---|
| 166 | #define _tremove remove
|
|---|
| 167 |
|
|---|
| 168 | #define _stricmp strcasecmp
|
|---|
| 169 | #define _strnicmp strncasecmp
|
|---|
| 170 | #define _tcsnicmp strncasecmp
|
|---|
| 171 |
|
|---|
| 172 | #endif // !WIN32
|
|---|
| 173 |
|
|---|
| 174 | // 64-bit calls are supplied by "normal" calls on Mac
|
|---|
| 175 | #if defined(PLATFORM_MAC)
|
|---|
| 176 | #define stat64 stat
|
|---|
| 177 | #define fstat64 fstat
|
|---|
| 178 | #define lseek64 lseek
|
|---|
| 179 | #define off64_t off_t
|
|---|
| 180 | #define O_LARGEFILE 0
|
|---|
| 181 | #endif
|
|---|
| 182 |
|
|---|
| 183 | // Platform-specific error codes for UNIX-based platforms
|
|---|
| 184 | #if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX)
|
|---|
| 185 | #define ERROR_SUCCESS 0
|
|---|
| 186 | #define ERROR_FILE_NOT_FOUND ENOENT
|
|---|
| 187 | #define ERROR_ACCESS_DENIED EPERM
|
|---|
| 188 | #define ERROR_INVALID_HANDLE EBADF
|
|---|
| 189 | #define ERROR_NOT_ENOUGH_MEMORY ENOMEM
|
|---|
| 190 | #define ERROR_NOT_SUPPORTED ENOTSUP
|
|---|
| 191 | #define ERROR_INVALID_PARAMETER EINVAL
|
|---|
| 192 | #define ERROR_DISK_FULL ENOSPC
|
|---|
| 193 | #define ERROR_ALREADY_EXISTS EEXIST
|
|---|
| 194 | #define ERROR_INSUFFICIENT_BUFFER ENOBUFS
|
|---|
| 195 | #define ERROR_BAD_FORMAT 1000 // No such error code under Linux
|
|---|
| 196 | #define ERROR_NO_MORE_FILES 1001 // No such error code under Linux
|
|---|
| 197 | #define ERROR_HANDLE_EOF 1002 // No such error code under Linux
|
|---|
| 198 | #define ERROR_CAN_NOT_COMPLETE 1003 // No such error code under Linux
|
|---|
| 199 | #define ERROR_FILE_CORRUPT 1004 // No such error code under Linux
|
|---|
| 200 | #endif
|
|---|
| 201 |
|
|---|
| 202 | #ifdef PLATFORM_LITTLE_ENDIAN
|
|---|
| 203 | #define BSWAP_INT16_UNSIGNED(a) (a)
|
|---|
| 204 | #define BSWAP_INT16_SIGNED(a) (a)
|
|---|
| 205 | #define BSWAP_INT32_UNSIGNED(a) (a)
|
|---|
| 206 | #define BSWAP_INT32_SIGNED(a) (a)
|
|---|
| 207 | #define BSWAP_INT64_SIGNED(a) (a)
|
|---|
| 208 | #define BSWAP_INT64_UNSIGNED(a) (a)
|
|---|
| 209 | #define BSWAP_ARRAY16_UNSIGNED(a,b) {}
|
|---|
| 210 | #define BSWAP_ARRAY32_UNSIGNED(a,b) {}
|
|---|
| 211 | #define BSWAP_ARRAY64_UNSIGNED(a,b) {}
|
|---|
| 212 | #define BSWAP_PART_HEADER(a) {}
|
|---|
| 213 | #define BSWAP_TMPQUSERDATA(a) {}
|
|---|
| 214 | #define BSWAP_TMPQHEADER(a) {}
|
|---|
| 215 | #else
|
|---|
| 216 |
|
|---|
| 217 | #ifdef __cplusplus
|
|---|
| 218 | extern "C" {
|
|---|
| 219 | #endif
|
|---|
| 220 | int16_t SwapInt16(uint16_t);
|
|---|
| 221 | uint16_t SwapUInt16(uint16_t);
|
|---|
| 222 | int32_t SwapInt32(uint32_t);
|
|---|
| 223 | uint32_t SwapUInt32(uint32_t);
|
|---|
| 224 | int64_t SwapInt64(uint64_t);
|
|---|
| 225 | uint64_t SwapUInt64(uint64_t);
|
|---|
| 226 | void ConvertUInt16Buffer(void * ptr, size_t length);
|
|---|
| 227 | void ConvertUInt32Buffer(void * ptr, size_t length);
|
|---|
| 228 | void ConvertUInt64Buffer(void * ptr, size_t length);
|
|---|
| 229 | void ConvertPartHeader(void * partHeader);
|
|---|
| 230 | void ConvertTMPQUserData(void *userData);
|
|---|
| 231 | void ConvertTMPQHeader(void *header);
|
|---|
| 232 | #ifdef __cplusplus
|
|---|
| 233 | }
|
|---|
| 234 | #endif
|
|---|
| 235 | #define BSWAP_INT16_SIGNED(a) SwapInt16((a))
|
|---|
| 236 | #define BSWAP_INT16_UNSIGNED(a) SwapUInt16((a))
|
|---|
| 237 | #define BSWAP_INT32_SIGNED(a) SwapInt32((a))
|
|---|
| 238 | #define BSWAP_INT32_UNSIGNED(a) SwapUInt32((a))
|
|---|
| 239 | #define BSWAP_INT64_SIGNED(a) SwapInt64((a))
|
|---|
| 240 | #define BSWAP_INT64_UNSIGNED(a) SwapUInt64((a))
|
|---|
| 241 | #define BSWAP_ARRAY16_UNSIGNED(a,b) ConvertUInt16Buffer((a),(b))
|
|---|
| 242 | #define BSWAP_ARRAY32_UNSIGNED(a,b) ConvertUInt32Buffer((a),(b))
|
|---|
| 243 | #define BSWAP_ARRAY64_UNSIGNED(a,b) ConvertUInt64Buffer((a),(b))
|
|---|
| 244 | #define BSWAP_PART_HEADER(a) ConvertPartHeader(a)
|
|---|
| 245 | #define BSWAP_TMPQUSERDATA(a) ConvertTMPQUserData((a))
|
|---|
| 246 | #define BSWAP_TMPQHEADER(a) ConvertTMPQHeader((a))
|
|---|
| 247 | #endif
|
|---|
| 248 |
|
|---|
| 249 | #endif // __STORMPORT_H__
|
|---|