32 #ifndef CPL_BASE_H_INCLUDED 33 #define CPL_BASE_H_INCLUDED 53 #if defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE) 57 #if defined(_WINDOWS) && !defined(WIN32) && !defined(_WIN32_WCE) 64 #if defined(_WIN32_WCE) 73 # ifndef _CRT_SECURE_NO_DEPRECATE 74 # define _CRT_SECURE_NO_DEPRECATE 76 # ifndef _CRT_NONSTDC_NO_DEPRECATE 77 # define _CRT_NONSTDC_NO_DEPRECATE 81 #include "cpl_config.h" 88 #if !defined(SIZEOF_INT) || SIZEOF_INT != 4 89 #error "Unexpected value for SIZEOF_INT" 92 #if !defined(SIZEOF_UNSIGNED_LONG) || (SIZEOF_UNSIGNED_LONG != 4 && SIZEOF_UNSIGNED_LONG != 8) 93 #error "Unexpected value for SIZEOF_UNSIGNED_LONG" 96 #if !defined(SIZEOF_VOIDP) || (SIZEOF_VOIDP != 4 && SIZEOF_VOIDP != 8) 97 #error "Unexpected value for SIZEOF_VOIDP" 111 #if defined(VSI_NEED_LARGEFILE64_SOURCE) && !defined(_LARGEFILE64_SOURCE) 112 # define _LARGEFILE64_SOURCE 1 121 #if defined(HAVE_ICONV) 122 # define CPL_RECODE_ICONV 125 #define CPL_RECODE_STUB 134 #if defined(__MINGW32__) 135 #ifndef __MSVCRT_VERSION__ 136 #define __MSVCRT_VERSION__ 0x0601 152 #if !defined(WIN32CE) 155 # include <wce_time.h> 156 # include <wce_errno.h> 160 #if defined(HAVE_ERRNO_H) 172 #if !(defined(WIN32) || defined(WIN32CE)) 173 # include <strings.h> 176 #if defined(HAVE_LIBDBMALLOC) && defined(HAVE_DBMALLOC_H) && defined(DEBUG) 178 # include <dbmalloc.h> 181 #if !defined(DBMALLOC) && defined(HAVE_DMALLOC_H) 183 # include <dmalloc.h> 194 #if UINT_MAX == 65535 196 typedef unsigned long GUInt32;
199 typedef unsigned int GUInt32;
202 typedef short GInt16;
203 typedef unsigned short GUInt16;
204 typedef unsigned char GByte;
207 #ifndef CPL_GBOOL_DEFINED 208 #define CPL_GBOOL_DEFINED 216 #if defined(WIN32) && defined(_MSC_VER) 218 #define VSI_LARGE_API_SUPPORTED 219 typedef __int64 GIntBig;
220 typedef unsigned __int64 GUIntBig;
222 #define GINTBIG_MIN ((GIntBig)(0x80000000) << 32) 223 #define GINTBIG_MAX (((GIntBig)(0x7FFFFFFF) << 32) | 0xFFFFFFFFU) 227 typedef long long GIntBig;
228 typedef unsigned long long GUIntBig;
230 #define GINTBIG_MIN ((GIntBig)(0x80000000) << 32) 231 #define GINTBIG_MAX (((GIntBig)(0x7FFFFFFF) << 32) | 0xFFFFFFFFU) 235 typedef long GIntBig;
236 typedef unsigned long GUIntBig;
238 #define GINTBIG_MIN INT_MIN 239 #define GINTBIG_MAX INT_MAX 242 #if SIZEOF_VOIDP == 8 243 typedef GIntBig GPtrDiff_t;
245 typedef int GPtrDiff_t;
248 #if defined(__MSVCRT__) || (defined(WIN32) && defined(_MSC_VER)) 249 #define CPL_FRMT_GB_WITHOUT_PREFIX "I64" 251 #define CPL_FRMT_GB_WITHOUT_PREFIX "ll" 253 #define CPL_FRMT_GB_WITHOUT_PREFIX "l" 256 #define CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d" 257 #define CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u" 260 #if defined(_MSC_VER) && (_MSC_VER <= 1200) 261 #define GUINTBIG_TO_DOUBLE(x) (double)(GIntBig)(x) 263 #define GUINTBIG_TO_DOUBLE(x) (double)(x) 270 # define CPL_C_START extern "C" { 278 #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL) 279 # define CPL_DLL __declspec(dllexport) 281 # if defined(USE_GCC_VISIBILITY_FLAG) 282 # define CPL_DLL __attribute__ ((visibility("default"))) 290 #ifdef CPL_OPTIONAL_APIS 291 # define CPL_ODLL CPL_DLL 297 #if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL) 298 # define CPL_STDCALL __stdcall 305 # define FORCE_CDECL __cdecl 311 #if (defined(__GNUC__) && !defined(__NO_INLINE__)) || defined(_MSC_VER) 312 #define HAS_CPL_INLINE 1 313 #define CPL_INLINE __inline 314 #elif defined(__SUNPRO_CC) 315 #define HAS_CPL_INLINE 1 316 #define CPL_INLINE inline 334 # define MIN(a,b) ((a<b) ? a : b) 335 # define MAX(a,b) ((a>b) ? a : b) 339 # define ABS(x) ((x<0) ? (-1*(x)) : x) 343 # define M_PI 3.14159265358979323846 352 # define CPLIsEqual(x,y) (fabs((x) - (y)) < 0.0000000000001) 359 # if defined(WIN32) || defined(WIN32CE) 360 # define STRCASECMP(a,b) (stricmp(a,b)) 361 # define STRNCASECMP(a,b,n) (strnicmp(a,b,n)) 363 # define STRCASECMP(a,b) (strcasecmp(a,b)) 364 # define STRNCASECMP(a,b,n) (strncasecmp(a,b,n)) 366 # define EQUALN(a,b,n) (STRNCASECMP(a,b,n)==0) 367 # define EQUAL(a,b) (STRCASECMP(a,b)==0) 371 int strcasecmp(
char * str1,
char * str2);
372 int strncasecmp(
char * str1,
char * str2,
int len);
373 char * strdup (
char *instr);
376 #ifndef CPL_THREADLOCAL 377 # define CPL_THREADLOCAL 391 # define CPLIsNan(x) _isnan(x) 392 # define CPLIsInf(x) (!_isnan(x) && !_finite(x)) 393 # define CPLIsFinite(x) _finite(x) 395 # define CPLIsNan(x) isnan(x) 397 # define CPLIsInf(x) isinf(x) 398 # define CPLIsFinite(x) (!isnan(x) && !isinf(x)) 400 # define CPLIsInf(x) FALSE 401 # define CPLIsFinite(x) (!isnan(x)) 412 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB) 416 #if ! ( defined(CPL_LSB) || defined(CPL_MSB) ) 421 # define CPL_IS_LSB 1 423 # define CPL_IS_LSB 0 430 #define CPL_SWAP16(x) \ 432 (((GUInt16)(x) & 0x00ffU) << 8) | \ 433 (((GUInt16)(x) & 0xff00U) >> 8) )) 435 #define CPL_SWAP16PTR(x) \ 437 GByte byTemp, *_pabyDataT = (GByte *) (x); \ 439 byTemp = _pabyDataT[0]; \ 440 _pabyDataT[0] = _pabyDataT[1]; \ 441 _pabyDataT[1] = byTemp; \ 444 #define CPL_SWAP32(x) \ 446 (((GUInt32)(x) & (GUInt32)0x000000ffUL) << 24) | \ 447 (((GUInt32)(x) & (GUInt32)0x0000ff00UL) << 8) | \ 448 (((GUInt32)(x) & (GUInt32)0x00ff0000UL) >> 8) | \ 449 (((GUInt32)(x) & (GUInt32)0xff000000UL) >> 24) )) 451 #define CPL_SWAP32PTR(x) \ 453 GByte byTemp, *_pabyDataT = (GByte *) (x); \ 455 byTemp = _pabyDataT[0]; \ 456 _pabyDataT[0] = _pabyDataT[3]; \ 457 _pabyDataT[3] = byTemp; \ 458 byTemp = _pabyDataT[1]; \ 459 _pabyDataT[1] = _pabyDataT[2]; \ 460 _pabyDataT[2] = byTemp; \ 463 #define CPL_SWAP64PTR(x) \ 465 GByte byTemp, *_pabyDataT = (GByte *) (x); \ 467 byTemp = _pabyDataT[0]; \ 468 _pabyDataT[0] = _pabyDataT[7]; \ 469 _pabyDataT[7] = byTemp; \ 470 byTemp = _pabyDataT[1]; \ 471 _pabyDataT[1] = _pabyDataT[6]; \ 472 _pabyDataT[6] = byTemp; \ 473 byTemp = _pabyDataT[2]; \ 474 _pabyDataT[2] = _pabyDataT[5]; \ 475 _pabyDataT[5] = byTemp; \ 476 byTemp = _pabyDataT[3]; \ 477 _pabyDataT[3] = _pabyDataT[4]; \ 478 _pabyDataT[4] = byTemp; \ 498 #define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p) 501 # define CPL_MSBWORD16(x) (x) 502 # define CPL_LSBWORD16(x) CPL_SWAP16(x) 503 # define CPL_MSBWORD32(x) (x) 504 # define CPL_LSBWORD32(x) CPL_SWAP32(x) 505 # define CPL_MSBPTR16(x) 506 # define CPL_LSBPTR16(x) CPL_SWAP16PTR(x) 507 # define CPL_MSBPTR32(x) 508 # define CPL_LSBPTR32(x) CPL_SWAP32PTR(x) 509 # define CPL_MSBPTR64(x) 510 # define CPL_LSBPTR64(x) CPL_SWAP64PTR(x) 512 # define CPL_LSBWORD16(x) (x) 513 # define CPL_MSBWORD16(x) CPL_SWAP16(x) 514 # define CPL_LSBWORD32(x) (x) 515 # define CPL_MSBWORD32(x) CPL_SWAP32(x) 516 # define CPL_LSBPTR16(x) 517 # define CPL_MSBPTR16(x) CPL_SWAP16PTR(x) 518 # define CPL_LSBPTR32(x) 519 # define CPL_MSBPTR32(x) CPL_SWAP32PTR(x) 520 # define CPL_LSBPTR64(x) 521 # define CPL_MSBPTR64(x) CPL_SWAP64PTR(x) 525 #define CPL_LSBINT16PTR(x) ((*(GByte*)(x)) | (*(((GByte*)(x))+1) << 8)) 528 #define CPL_LSBINT32PTR(x) ((*(GByte*)(x)) | (*(((GByte*)(x))+1) << 8) | \ 529 (*(((GByte*)(x))+2) << 16) | (*(((GByte*)(x))+3) << 24)) 532 #define CPL_LSBSINT16PTR(x) ((GInt16) CPL_LSBINT16PTR(x)) 535 #define CPL_LSBUINT16PTR(x) ((GUInt16)CPL_LSBINT16PTR(x)) 538 #define CPL_LSBSINT32PTR(x) ((GInt32) CPL_LSBINT32PTR(x)) 541 #define CPL_LSBUINT32PTR(x) ((GUInt32)CPL_LSBINT32PTR(x)) 545 #ifndef UNREFERENCED_PARAM 546 # ifdef UNREFERENCED_PARAMETER 547 # define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param) 549 # define UNREFERENCED_PARAM(param) ((void)param) 561 #ifndef DISABLE_CVSID 562 #if defined(__GNUC__) && __GNUC__ >= 4 563 # define CPL_CVSID(string) static char cpl_cvsid[] __attribute__((used)) = string; 565 # define CPL_CVSID(string) static char cpl_cvsid[] = string; \ 566 static char *cvsid_aw() { return( cvsid_aw() ? ((char *) NULL) : cpl_cvsid ); } 569 # define CPL_CVSID(string) 573 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) 574 # define CPL_NULL_TERMINATED __attribute__((__sentinel__)) 576 # define CPL_NULL_TERMINATED 579 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP) 580 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx))) 582 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx ) 585 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) 586 #define CPL_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 588 #define CPL_WARN_UNUSED_RESULT 591 #if defined(__GNUC__) && __GNUC__ >= 4 592 # define CPL_UNUSED __attribute((__unused__)) 598 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP) 599 #define CPL_NO_RETURN __attribute__((noreturn)) 601 #define CPL_NO_RETURN 604 #if !defined(DOXYGEN_SKIP) 605 #if defined(__has_extension) 606 #if __has_extension(attribute_deprecated_with_message) 608 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated(x))) 610 #define CPL_WARN_DEPRECATED(x) 612 #elif defined(__GNUC__) 613 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated)) 615 #define CPL_WARN_DEPRECATED(x) 619 #ifdef WARN_STANDARD_PRINTF 620 int vsnprintf(
char *str,
size_t size,
const char* fmt, va_list args) CPL_WARN_DEPRECATED(
"Use CPLvsnprintf() instead");
621 int snprintf(
char *str,
size_t size,
const char* fmt, ...) CPL_PRINT_FUNC_FORMAT(3,4) CPL_WARN_DEPRECATED("Use CPLsnprintf() instead");
622 int sprintf(
char *str, const
char* fmt, ...) CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_DEPRECATED("Use CPLsprintf() instead");