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 #define STORMAPI 31 32 #ifndef __cplusplus 33 #define bool char 34 #define true 1 35 #define false 0 36 #endif 37 38 //----------------------------------------------------------------------------- 39 // Defines for Windows 40 41 #if !defined(PLATFORM_DEFINED) && defined(_WIN32) 42 43 // In MSVC 8.0, there are some functions declared as deprecated. 44 #if _MSC_VER >= 1400 45 #define _CRT_SECURE_NO_DEPRECATE 46 #define _CRT_NON_CONFORMING_SWPRINTFS 47 #endif 48 49 #include <tchar.h> 50 #include <assert.h> 51 #include <ctype.h> 52 #include <stdio.h> 53 54 // Suppress definitions of `min` and `max` macros by <windows.h>: 55 #define NOMINMAX 1 56 #include <windows.h> 57 58 #include <wininet.h> 59 #define PLATFORM_LITTLE_ENDIAN 60 61 #ifdef _WIN64 62 #define PLATFORM_64BIT 63 #else 64 #define PLATFORM_32BIT 65 #endif 66 67 #define PLATFORM_WINDOWS 68 #define PLATFORM_DEFINED // The platform is known now 69 70 #endif 71 72 //----------------------------------------------------------------------------- 73 // Defines for Mac 74 75 #if !defined(PLATFORM_DEFINED) && defined(__APPLE__) // Mac BSD API 76 77 // Macintosh 78 #include <sys/types.h> 79 #include <sys/stat.h> 80 #include <sys/mman.h> 81 #include <unistd.h> 82 #include <fcntl.h> 83 #include <stdlib.h> 84 #include <stdio.h> 85 #include <string.h> 86 #include <ctype.h> 87 #include <assert.h> 88 #include <errno.h> 89 90 // Support for PowerPC on Mac OS X 91 #if (__ppc__ == 1) || (__POWERPC__ == 1) || (_ARCH_PPC == 1) 92 #include <stdint.h> 93 #include <CoreFoundation/CFByteOrder.h> 94 #endif 95 96 #define PKEXPORT 97 #define __SYS_ZLIB 98 #define __SYS_BZLIB 99 100 #ifndef __BIG_ENDIAN__ 101 #define PLATFORM_LITTLE_ENDIAN 102 #endif 103 104 #define PLATFORM_MAC 105 #define PLATFORM_DEFINED // The platform is known now 106 107 #endif 108 109 #if !defined(PLATFORM_DEFINED) && defined(__HAIKU__) 110 111 #include <sys/types.h> 112 #include <sys/stat.h> 113 #include <sys/mman.h> 114 #include <fcntl.h> 115 #include <unistd.h> 116 #include <stdint.h> 117 #include <stdlib.h> 118 #include <stdio.h> 119 #include <stdarg.h> 120 #include <string.h> 121 #include <ctype.h> 122 #include <assert.h> 123 #include <errno.h> 124 125 #ifndef __BIG_ENDIAN__ 126 #define PLATFORM_LITTLE_ENDIAN 127 #endif 128 129 #define PLATFORM_HAIKU 130 #define PLATFORM_DEFINED // The platform is known now 131 132 #endif 133 134 #if !defined(PLATFORM_DEFINED) && defined(__AMIGA__) 135 136 #include <sys/types.h> 137 #include <sys/stat.h> 138 #include <fcntl.h> 139 #include <unistd.h> 140 #include <stdint.h> 141 #include <stdlib.h> 142 #include <stdio.h> 143 #include <stdarg.h> 144 #include <string.h> 145 #include <ctype.h> 146 #include <assert.h> 147 #include <errno.h> 148 149 #define PLATFORM_AMIGA 150 #define PLATFORM_DEFINED 151 152 #endif 153 154 #if !defined(PLATFORM_DEFINED) && defined(__SWITCH__) 155 #include <sys/types.h> 156 #include <sys/stat.h> 157 #include <fcntl.h> 158 #include <unistd.h> 159 #include <stdint.h> 160 #include <stdlib.h> 161 #include <stdio.h> 162 #include <stdarg.h> 163 #include <string.h> 164 #include <strings.h> 165 #include <ctype.h> 166 #include <assert.h> 167 #include <errno.h> 168 169 #ifndef __BIG_ENDIAN__ 170 #define PLATFORM_LITTLE_ENDIAN 171 #endif 172 173 #define PLATFORM_SWITCH 174 #define PLATFORM_DEFINED 175 176 #endif 177 178 #if !defined(PLATFORM_DEFINED) && defined(__3DS__) 179 #include <sys/stat.h> 180 #include <fcntl.h> 181 #include <unistd.h> 182 #include <stdint.h> 183 #include <stdlib.h> 184 #include <stdio.h> 185 #include <stdarg.h> 186 #include <string.h> 187 #include <strings.h> 188 #include <ctype.h> 189 #include <assert.h> 190 #include <errno.h> 191 192 #define PLATFORM_LITTLE_ENDIAN 193 194 #define PLATFORM_CTR 195 #define PLATFORM_DEFINED 196 197 #endif 198 199 #if !defined(PLATFORM_DEFINED) && defined(__vita__) 200 #include <sys/types.h> 201 #include <sys/stat.h> 202 #include <fcntl.h> 203 #include <unistd.h> 204 #include <stdint.h> 205 #include <stdlib.h> 206 #include <stdio.h> 207 #include <stdarg.h> 208 #include <string.h> 209 #include <strings.h> 210 #include <ctype.h> 211 #include <assert.h> 212 #include <errno.h> 213 214 #ifndef __BIG_ENDIAN__ 215 #define PLATFORM_LITTLE_ENDIAN 216 #endif 217 218 #define PLATFORM_VITA 219 #define PLATFORM_DEFINED 220 221 #endif 222 223 //----------------------------------------------------------------------------- 224 // Assumption: we are not on Windows nor Macintosh, so this must be linux *grin* 225 226 #if !defined(PLATFORM_DEFINED) 227 228 #include <sys/types.h> 229 #include <sys/stat.h> 230 #ifndef __vita__ 231 #include <sys/mman.h> 232 #endif 233 #include <fcntl.h> 234 #include <unistd.h> 235 #include <stdint.h> 236 #include <stdlib.h> 237 #include <stdio.h> 238 #include <stdarg.h> 239 #include <string.h> 240 #include <strings.h> 241 #include <ctype.h> 242 #include <assert.h> 243 #include <errno.h> 244 245 #ifndef __BIG_ENDIAN__ 246 #define PLATFORM_LITTLE_ENDIAN 247 #endif 248 249 #define PLATFORM_LINUX 250 #define PLATFORM_DEFINED 251 252 #endif 253 254 //----------------------------------------------------------------------------- 255 // Definition of Windows-specific types for non-Windows platforms 256 257 #ifndef PLATFORM_WINDOWS 258 #if __LP64__ 259 #define PLATFORM_64BIT 260 #else 261 #define PLATFORM_32BIT 262 #endif 263 264 // Typedefs for ANSI C 265 typedef unsigned char BYTE; 266 typedef int LONG; 267 typedef unsigned short USHORT; 268 typedef unsigned int DWORD; 269 typedef unsigned long DWORD_PTR; 270 typedef long LONG_PTR; 271 typedef long INT_PTR; 272 typedef long long LONGLONG; 273 typedef unsigned long long ULONGLONG; 274 typedef void * HANDLE; 275 typedef void * LPOVERLAPPED; // Unsupported on Linux and Mac 276 typedef char TCHAR; 277 typedef unsigned int LCID; 278 typedef LONG * PLONG; 279 typedef DWORD * LPDWORD; 280 typedef BYTE * LPBYTE; 281 typedef const char * LPCTSTR; 282 typedef const char * LPCSTR; 283 typedef char * LPTSTR; 284 typedef char * LPSTR; 285 286 #ifdef PLATFORM_32BIT 287 #define _LZMA_UINT32_IS_ULONG 288 #endif 289 290 // Some Windows-specific defines 291 #ifndef MAX_PATH 292 #define MAX_PATH 1024 293 #endif 294 295 #ifndef _countof 296 #define _countof(x) (sizeof(x) / sizeof(x[0])) 297 #endif 298 299 #define WINAPI __attribute__((stdcall)) 300 301 #define FILE_BEGIN SEEK_SET 302 #define FILE_CURRENT SEEK_CUR 303 #define FILE_END SEEK_END 304 305 #define _T(x) x 306 #define _tcslen strlen 307 #define _tcscpy strcpy 308 #define _tcscat strcat 309 #define _tcschr strchr 310 #define _tcsrchr strrchr 311 #define _tcsstr strstr 312 #define _tcsnicmp strncasecmp 313 #define _tprintf printf 314 #define _stprintf sprintf 315 #define _tremove remove 316 #define _tmain main 317 318 #define _stricmp strcasecmp 319 #define _strnicmp strncasecmp 320 #define _tcsicmp strcasecmp 321 #define _tcsnicmp strncasecmp 322 323 #endif // !PLATFORM_WINDOWS 324 325 // 64-bit calls are supplied by "normal" calls on Mac 326 #if defined(PLATFORM_MAC) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH) || defined(PLATFORM_CTR) || defined(PLATFORM_VITA) 327 #define stat64 stat 328 #define fstat64 fstat 329 #define lseek64 lseek 330 #define ftruncate64 ftruncate 331 #define off64_t off_t 332 #define O_LARGEFILE 0 333 #endif 334 335 // Platform-specific error codes for UNIX-based platforms 336 #if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH) || defined(PLATFORM_CTR) || defined(PLATFORM_VITA) 337 #define ERROR_SUCCESS 0 338 #define ERROR_FILE_NOT_FOUND ENOENT 339 #define ERROR_ACCESS_DENIED EPERM 340 #define ERROR_INVALID_HANDLE EBADF 341 #define ERROR_NOT_ENOUGH_MEMORY ENOMEM 342 #define ERROR_NOT_SUPPORTED ENOTSUP 343 #define ERROR_INVALID_PARAMETER EINVAL 344 #define ERROR_NEGATIVE_SEEK EINVAL 345 #define ERROR_DISK_FULL ENOSPC 346 #define ERROR_ALREADY_EXISTS EEXIST 347 #define ERROR_INSUFFICIENT_BUFFER ENOBUFS 348 #define ERROR_BAD_FORMAT 1000 // No such error code under Linux 349 #define ERROR_NO_MORE_FILES 1001 // No such error code under Linux 350 #define ERROR_HANDLE_EOF 1002 // No such error code under Linux 351 #define ERROR_CAN_NOT_COMPLETE 1003 // No such error code under Linux 352 #define ERROR_FILE_CORRUPT 1004 // No such error code under Linux 353 #endif 354 355 //----------------------------------------------------------------------------- 356 // Swapping functions 357 358 #ifdef PLATFORM_LITTLE_ENDIAN 359 #define BSWAP_INT16_UNSIGNED(a) (a) 360 #define BSWAP_INT16_SIGNED(a) (a) 361 #define BSWAP_INT32_UNSIGNED(a) (a) 362 #define BSWAP_INT32_SIGNED(a) (a) 363 #define BSWAP_INT64_SIGNED(a) (a) 364 #define BSWAP_INT64_UNSIGNED(a) (a) 365 #define BSWAP_ARRAY16_UNSIGNED(a,b) {} 366 #define BSWAP_ARRAY32_UNSIGNED(a,b) {} 367 #define BSWAP_ARRAY64_UNSIGNED(a,b) {} 368 #define BSWAP_PART_HEADER(a) {} 369 #define BSWAP_TMPQHEADER(a,b) {} 370 #define BSWAP_TMPKHEADER(a) {} 371 #else 372 373 #ifdef __cplusplus 374 extern "C" { 375 #endif 376 int16_t SwapInt16(uint16_t); 377 uint16_t SwapUInt16(uint16_t); 378 int32_t SwapInt32(uint32_t); 379 uint32_t SwapUInt32(uint32_t); 380 int64_t SwapInt64(uint64_t); 381 uint64_t SwapUInt64(uint64_t); 382 void ConvertUInt16Buffer(void * ptr, size_t length); 383 void ConvertUInt32Buffer(void * ptr, size_t length); 384 void ConvertUInt64Buffer(void * ptr, size_t length); 385 void ConvertTMPQUserData(void *userData); 386 void ConvertTMPQHeader(void *header, uint16_t wPart); 387 void ConvertTMPKHeader(void *header); 388 #ifdef __cplusplus 389 } 390 #endif 391 #define BSWAP_INT16_SIGNED(a) SwapInt16((a)) 392 #define BSWAP_INT16_UNSIGNED(a) SwapUInt16((a)) 393 #define BSWAP_INT32_SIGNED(a) SwapInt32((a)) 394 #define BSWAP_INT32_UNSIGNED(a) SwapUInt32((a)) 395 #define BSWAP_INT64_SIGNED(a) SwapInt64((a)) 396 #define BSWAP_INT64_UNSIGNED(a) SwapUInt64((a)) 397 #define BSWAP_ARRAY16_UNSIGNED(a,b) ConvertUInt16Buffer((a),(b)) 398 #define BSWAP_ARRAY32_UNSIGNED(a,b) ConvertUInt32Buffer((a),(b)) 399 #define BSWAP_ARRAY64_UNSIGNED(a,b) ConvertUInt64Buffer((a),(b)) 400 #define BSWAP_TMPQHEADER(a,b) ConvertTMPQHeader((a),(b)) 401 #define BSWAP_TMPKHEADER(a) ConvertTMPKHeader((a)) 402 403 #endif 404 405 //----------------------------------------------------------------------------- 406 // Macro for deprecated symbols 407 408 /* 409 #ifdef _MSC_VER 410 #if _MSC_FULL_VER >= 140050320 411 #define STORMLIB_DEPRECATED(_Text) __declspec(deprecated(_Text)) 412 #else 413 #define STORMLIB_DEPRECATED(_Text) __declspec(deprecated) 414 #endif 415 #else 416 #ifdef __GNUC__ 417 #define STORMLIB_DEPRECATED(_Text) __attribute__((deprecated)) 418 #else 419 #define STORMLIB_DEPRECATED(_Text) __attribute__((deprecated(_Text))) 420 #endif 421 #endif 422 423 // When a flag is deprecated, use this macro 424 #ifndef _STORMLIB_NO_DEPRECATE 425 #define STORMLIB_DEPRECATED_FLAG(type, oldflag, newflag) \ 426 const STORMLIB_DEPRECATED(#oldflag " is deprecated. Use " #newflag ". To supress this warning, define _STORMLIB_NO_DEPRECATE") static type oldflag = (type)newflag; 427 #else 428 #define STORMLIB_DEPRECATED_FLAG(type, oldflag, newflag) static type oldflag = (type)newflag; 429 #endif 430 */ 431 432 // 433 // MINIWIN changes 434 // 435 436 #define bool int 437 438 #endif // __STORMPORT_H__ 439