32 #ifndef CPL_BASE_H_INCLUDED 33 #define CPL_BASE_H_INCLUDED 45 #if defined(_WIN32) && !defined(WIN32) 49 #if defined(_WINDOWS) && !defined(WIN32) 58 # ifndef _CRT_SECURE_NO_DEPRECATE 59 # define _CRT_SECURE_NO_DEPRECATE 61 # ifndef _CRT_NONSTDC_NO_DEPRECATE 62 # define _CRT_NONSTDC_NO_DEPRECATE 66 #include "cpl_config.h" 73 #if !defined(SIZEOF_INT) || SIZEOF_INT != 4 74 #error "Unexpected value for SIZEOF_INT" 77 #if !defined(SIZEOF_UNSIGNED_LONG) || (SIZEOF_UNSIGNED_LONG != 4 && SIZEOF_UNSIGNED_LONG != 8) 78 #error "Unexpected value for SIZEOF_UNSIGNED_LONG" 81 #if !defined(SIZEOF_VOIDP) || (SIZEOF_VOIDP != 4 && SIZEOF_VOIDP != 8) 82 #error "Unexpected value for SIZEOF_VOIDP" 95 #if defined(VSI_NEED_LARGEFILE64_SOURCE) && !defined(_LARGEFILE64_SOURCE) 96 # define _LARGEFILE64_SOURCE 1 105 #if defined(HAVE_ICONV) 106 # define CPL_RECODE_ICONV 109 #define CPL_RECODE_STUB 119 #if defined(__MINGW32__) 120 #ifndef __MSVCRT_VERSION__ 121 #define __MSVCRT_VERSION__ 0x0700 126 #if defined(GDAL_COMPILATION) && defined(__sun__) && __STDC_VERSION__ >= 201112L && _XOPEN_SOURCE < 600 130 #define _XOPEN_SOURCE 600 147 #if defined(HAVE_ERRNO_H) 160 # include <strings.h> 163 #if defined(HAVE_LIBDBMALLOC) && defined(HAVE_DBMALLOC_H) && defined(DEBUG) 165 # include <dbmalloc.h> 168 #if !defined(DBMALLOC) && defined(HAVE_DMALLOC_H) 170 # include <dmalloc.h> 185 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) 186 # if !(__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900)) 187 # error Must have C++11 or newer. 189 # if __cplusplus >= 201402L 190 # define HAVE_CXX14 1 198 #if UINT_MAX == 65535 216 #ifndef CPL_GBOOL_DEFINED 218 #define CPL_GBOOL_DEFINED 226 #define CPL_STATIC_CAST(type, expr) static_cast<type>(expr) 227 #define CPL_REINTERPRET_CAST(type, expr) reinterpret_cast<type>(expr) 229 #define CPL_STATIC_CAST(type, expr) ((type)(expr)) 230 #define CPL_REINTERPRET_CAST(type, expr) ((type)(expr)) 238 #if defined(WIN32) && defined(_MSC_VER) 239 #define VSI_LARGE_API_SUPPORTED 252 #define GINTBIG_MIN (CPL_STATIC_CAST(GIntBig, 0x80000000) << 32) 254 #define GINTBIG_MAX ((CPL_STATIC_CAST(GIntBig, 0x7FFFFFFF) << 32) | 0xFFFFFFFFU) 256 #define GUINTBIG_MAX ((CPL_STATIC_CAST(GUIntBig, 0xFFFFFFFFU) << 32) | 0xFFFFFFFFU) 259 #define CPL_HAS_GINT64 1 270 #define GINT64_MIN GINTBIG_MIN 272 #define GINT64_MAX GINTBIG_MAX 274 #define GUINT64_MAX GUINTBIG_MAX 278 #error "64bit integer support required" 282 #if SIZEOF_VOIDP == 8 290 #ifdef GDAL_COMPILATION 293 typedef uintptr_t GUIntptr_t;
294 #elif SIZEOF_VOIDP == 8 297 typedef unsigned int GUIntptr_t;
300 #define CPL_IS_ALIGNED(ptr, quant) ((CPL_REINTERPRET_CAST(GUIntptr_t, CPL_STATIC_CAST(const void*, ptr)) % (quant)) == 0) 304 #if defined(__MSVCRT__) || (defined(WIN32) && defined(_MSC_VER)) 305 #define CPL_FRMT_GB_WITHOUT_PREFIX "I64" 308 #define CPL_FRMT_GB_WITHOUT_PREFIX "ll" 310 #define CPL_FRMT_GB_WITHOUT_PREFIX "l" 314 #define CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d" 316 #define CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u" 319 #define GUINTBIG_TO_DOUBLE(x) CPL_STATIC_CAST(double, x) 323 #ifdef COMPAT_WITH_ICC_CONVERSION_CHECK 324 #define CPL_INT64_FITS_ON_INT32(x) ((x) >= INT_MIN && (x) <= INT_MAX) 326 #define CPL_INT64_FITS_ON_INT32(x) (CPL_STATIC_CAST(GIntBig, CPL_STATIC_CAST(int, x)) == (x)) 335 # define CPL_C_START extern "C" { 344 #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL) 345 # define CPL_DLL __declspec(dllexport) 347 # if defined(USE_GCC_VISIBILITY_FLAG) 348 # define CPL_DLL __attribute__ ((visibility("default"))) 357 #ifdef CPL_OPTIONAL_APIS 358 # define CPL_ODLL CPL_DLL 365 #if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL) 366 # define CPL_STDCALL __stdcall 374 # define FORCE_CDECL __cdecl 382 #if (defined(__GNUC__) && !defined(__NO_INLINE__)) || defined(_MSC_VER) 383 #define HAS_CPL_INLINE 1 384 #define CPL_INLINE __inline 385 #elif defined(__SUNPRO_CC) 386 #define HAS_CPL_INLINE 1 387 #define CPL_INLINE inline 395 # define MIN(a,b) (((a)<(b)) ? (a) : (b)) 397 # define MAX(a,b) (((a)>(b)) ? (a) : (b)) 402 # define ABS(x) (((x)<0) ? (-1*(x)) : (x)) 407 # define M_PI 3.14159265358979323846 418 # define CPLIsEqual(x,y) (fabs((x) - (y)) < 0.0000000000001) 427 #if defined(AFL_FRIENDLY) && defined(__GNUC__) 429 static inline int CPL_afl_friendly_memcmp(
const void* ptr1,
const void* ptr2,
size_t len)
430 __attribute__((always_inline));
432 static inline int CPL_afl_friendly_memcmp(
const void* ptr1,
const void* ptr2,
size_t len)
434 const unsigned char* bptr1 = (
const unsigned char*)ptr1;
435 const unsigned char* bptr2 = (
const unsigned char*)ptr2;
438 unsigned char b1 = *(bptr1++);
439 unsigned char b2 = *(bptr2++);
440 if( b1 != b2 )
return b1 - b2;
445 static inline int CPL_afl_friendly_strcmp(
const char* ptr1,
const char* ptr2)
446 __attribute__((always_inline));
448 static inline int CPL_afl_friendly_strcmp(
const char* ptr1,
const char* ptr2)
450 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
451 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
454 unsigned char ch1 = *(usptr1++);
455 unsigned char ch2 = *(usptr2++);
456 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
460 static inline int CPL_afl_friendly_strncmp(
const char* ptr1,
const char* ptr2,
size_t len)
461 __attribute__((always_inline));
463 static inline int CPL_afl_friendly_strncmp(
const char* ptr1,
const char* ptr2,
size_t len)
465 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
466 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
469 unsigned char ch1 = *(usptr1++);
470 unsigned char ch2 = *(usptr2++);
471 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
476 static inline int CPL_afl_friendly_strcasecmp(
const char* ptr1,
const char* ptr2)
477 __attribute__((always_inline));
479 static inline int CPL_afl_friendly_strcasecmp(
const char* ptr1,
const char* ptr2)
481 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
482 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
485 unsigned char ch1 = *(usptr1++);
486 unsigned char ch2 = *(usptr2++);
487 ch1 = (
unsigned char)toupper(ch1);
488 ch2 = (
unsigned char)toupper(ch2);
489 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
493 static inline int CPL_afl_friendly_strncasecmp(
const char* ptr1,
const char* ptr2,
size_t len)
494 __attribute__((always_inline));
496 static inline int CPL_afl_friendly_strncasecmp(
const char* ptr1,
const char* ptr2,
size_t len)
498 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
499 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
502 unsigned char ch1 = *(usptr1++);
503 unsigned char ch2 = *(usptr2++);
504 ch1 = (
unsigned char)toupper(ch1);
505 ch2 = (
unsigned char)toupper(ch2);
506 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
511 static inline char* CPL_afl_friendly_strstr(
const char* haystack,
const char* needle)
512 __attribute__((always_inline));
514 static inline char* CPL_afl_friendly_strstr(
const char* haystack,
const char* needle)
516 const char* ptr_haystack = haystack;
519 const char* ptr_haystack2 = ptr_haystack;
520 const char* ptr_needle = needle;
523 char ch1 = *(ptr_haystack2++);
524 char ch2 = *(ptr_needle++);
526 return (
char*)ptr_haystack;
530 if( *ptr_haystack == 0 )
538 #define memcmp CPL_afl_friendly_memcmp 539 #define strcmp CPL_afl_friendly_strcmp 540 #define strncmp CPL_afl_friendly_strncmp 541 #define strcasecmp CPL_afl_friendly_strcasecmp 542 #define strncasecmp CPL_afl_friendly_strncasecmp 543 #define strstr CPL_afl_friendly_strstr 548 # define STRCASECMP(a,b) (stricmp(a,b)) 549 # define STRNCASECMP(a,b,n) (strnicmp(a,b,n)) 552 # define STRCASECMP(a,b) (strcasecmp(a,b)) 554 # define STRNCASECMP(a,b,n) (strncasecmp(a,b,n)) 557 # define EQUALN(a,b,n) (STRNCASECMP(a,b,n)==0) 559 # define EQUAL(a,b) (STRCASECMP(a,b)==0) 566 #ifndef STARTS_WITH_CI 568 #define STARTS_WITH(a,b) (strncmp(a,b,strlen(b)) == 0) 570 #define STARTS_WITH_CI(a,b) EQUALN(a,b,strlen(b)) 574 #ifndef CPL_THREADLOCAL 575 # define CPL_THREADLOCAL 590 # define CPLIsNan(x) _isnan(x) 591 # define CPLIsInf(x) (!_isnan(x) && !_finite(x)) 592 # define CPLIsFinite(x) _finite(x) 593 #elif defined(__GNUC__) && ( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 4 ) ) 596 # define CPLIsNan(x) __builtin_isnan(x) 597 # define CPLIsInf(x) __builtin_isinf(x) 598 # define CPLIsFinite(x) __builtin_isfinite(x) 599 #elif defined(__cplusplus) && defined(HAVE_STD_IS_NAN) && HAVE_STD_IS_NAN 604 static inline int CPLIsNan(
float f) {
return std::isnan(f); }
605 static inline int CPLIsNan(
double f) {
return std::isnan(f); }
606 static inline int CPLIsInf(
float f) {
return std::isinf(f); }
607 static inline int CPLIsInf(
double f) {
return std::isinf(f); }
608 static inline int CPLIsFinite(
float f) {
return std::isfinite(f); }
609 static inline int CPLIsFinite(
double f) {
return std::isfinite(f); }
613 #if defined(__cplusplus) && defined(__GNUC__) && defined(__linux) && !defined(__ANDROID__) && !defined(CPL_SUPRESS_CPLUSPLUS) 617 static inline int CPLIsNan(
float f) {
return __isnanf(f); }
618 static inline int CPLIsNan(
double f) {
return __isnan(f); }
619 static inline int CPLIsInf(
float f) {
return __isinff(f); }
620 static inline int CPLIsInf(
double f) {
return __isinf(f); }
621 static inline int CPLIsFinite(
float f) {
return !__isnanf(f) && !__isinff(f); }
622 static inline int CPLIsFinite(
double f) {
return !__isnan(f) && !__isinf(f); }
625 # define CPLIsNan(x) isnan(x) 626 # if defined(isinf) || defined(__FreeBSD__) 628 # define CPLIsInf(x) isinf(x) 630 # define CPLIsFinite(x) (!isnan(x) && !isinf(x)) 631 # elif defined(__sun__) 633 # define CPLIsInf(x) (!finite(x) && !isnan(x)) 634 # define CPLIsFinite(x) finite(x) 636 # define CPLIsInf(x) (0) 637 # define CPLIsFinite(x) (!isnan(x)) 650 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB) 654 #if ! ( defined(CPL_LSB) || defined(CPL_MSB) ) 659 # define CPL_IS_LSB 1 661 # define CPL_IS_LSB 0 665 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) 670 template <
bool b>
struct CPLStaticAssert {};
671 template<>
struct CPLStaticAssert<true>
673 static void my_function() {}
678 #define CPL_STATIC_ASSERT(x) CPLStaticAssert<x>::my_function() 679 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x) CPL_STATIC_ASSERT(x) 683 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x) 693 #define CPL_SWAP16(x) CPL_STATIC_CAST(GUInt16, (CPL_STATIC_CAST(GUInt16, x) << 8) | (CPL_STATIC_CAST(GUInt16, x) >> 8) ) 695 #if defined(HAVE_GCC_BSWAP) && (defined(__i386__) || defined(__x86_64__)) 699 #include <x86intrin.h> 701 #define CPL_SWAP32(x) CPL_STATIC_CAST(GUInt32, __builtin_bswap32(CPL_STATIC_CAST(GUInt32, x))) 703 #define CPL_SWAP64(x) CPL_STATIC_CAST(GUInt64, __builtin_bswap64(CPL_STATIC_CAST(GUInt64, x))) 704 #elif defined(_MSC_VER) 705 #define CPL_SWAP32(x) CPL_STATIC_CAST(GUInt32, _byteswap_ulong(CPL_STATIC_CAST(GUInt32, x))) 706 #define CPL_SWAP64(x) CPL_STATIC_CAST(GUInt64, _byteswap_uint64(CPL_STATIC_CAST(GUInt64, x))) 709 #define CPL_SWAP32(x) \ 710 CPL_STATIC_CAST(GUInt32, \ 711 ((CPL_STATIC_CAST(GUInt32, x) & 0x000000ffU) << 24) | \ 712 ((CPL_STATIC_CAST(GUInt32, x) & 0x0000ff00U) << 8) | \ 713 ((CPL_STATIC_CAST(GUInt32, x) & 0x00ff0000U) >> 8) | \ 714 ((CPL_STATIC_CAST(GUInt32, x) & 0xff000000U) >> 24) ) 717 #define CPL_SWAP64(x) \ 718 ((CPL_STATIC_CAST(GUInt64, CPL_SWAP32(CPL_STATIC_CAST(GUInt32, x))) << 32) | \ 719 (CPL_STATIC_CAST(GUInt64, CPL_SWAP32(CPL_STATIC_CAST(GUInt32, CPL_STATIC_CAST(GUInt64, x) >> 32))))) 724 #define CPL_SWAP16PTR(x) \ 726 GByte byTemp, *_pabyDataT = CPL_REINTERPRET_CAST(GByte*, x); \ 727 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2); \ 729 byTemp = _pabyDataT[0]; \ 730 _pabyDataT[0] = _pabyDataT[1]; \ 731 _pabyDataT[1] = byTemp; \ 734 #if defined(MAKE_SANITIZE_HAPPY) || !(defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64)) 737 #define CPL_SWAP32PTR(x) \ 739 GByte byTemp, *_pabyDataT = CPL_REINTERPRET_CAST(GByte*, x); \ 740 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4); \ 742 byTemp = _pabyDataT[0]; \ 743 _pabyDataT[0] = _pabyDataT[3]; \ 744 _pabyDataT[3] = byTemp; \ 745 byTemp = _pabyDataT[1]; \ 746 _pabyDataT[1] = _pabyDataT[2]; \ 747 _pabyDataT[2] = byTemp; \ 751 #define CPL_SWAP64PTR(x) \ 753 GByte byTemp, *_pabyDataT = CPL_REINTERPRET_CAST(GByte*, x); \ 754 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8); \ 756 byTemp = _pabyDataT[0]; \ 757 _pabyDataT[0] = _pabyDataT[7]; \ 758 _pabyDataT[7] = byTemp; \ 759 byTemp = _pabyDataT[1]; \ 760 _pabyDataT[1] = _pabyDataT[6]; \ 761 _pabyDataT[6] = byTemp; \ 762 byTemp = _pabyDataT[2]; \ 763 _pabyDataT[2] = _pabyDataT[5]; \ 764 _pabyDataT[5] = byTemp; \ 765 byTemp = _pabyDataT[3]; \ 766 _pabyDataT[3] = _pabyDataT[4]; \ 767 _pabyDataT[4] = byTemp; \ 773 #define CPL_SWAP32PTR(x) \ 777 memcpy(&_n32, _lx, 4); \ 778 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4); \ 779 _n32 = CPL_SWAP32(_n32); \ 780 memcpy(_lx, &_n32, 4); \ 784 #define CPL_SWAP64PTR(x) \ 788 memcpy(&_n64, _lx, 8); \ 789 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8); \ 790 _n64 = CPL_SWAP64(_n64); \ 791 memcpy(_lx, &_n64, 8); \ 797 #define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p) 800 # define CPL_MSBWORD16(x) (x) 801 # define CPL_LSBWORD16(x) CPL_SWAP16(x) 802 # define CPL_MSBWORD32(x) (x) 803 # define CPL_LSBWORD32(x) CPL_SWAP32(x) 804 # define CPL_MSBPTR16(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2) 805 # define CPL_LSBPTR16(x) CPL_SWAP16PTR(x) 806 # define CPL_MSBPTR32(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4) 807 # define CPL_LSBPTR32(x) CPL_SWAP32PTR(x) 808 # define CPL_MSBPTR64(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8) 809 # define CPL_LSBPTR64(x) CPL_SWAP64PTR(x) 812 # define CPL_LSBWORD16(x) (x) 814 # define CPL_MSBWORD16(x) CPL_SWAP16(x) 816 # define CPL_LSBWORD32(x) (x) 818 # define CPL_MSBWORD32(x) CPL_SWAP32(x) 820 # define CPL_LSBPTR16(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2) 822 # define CPL_MSBPTR16(x) CPL_SWAP16PTR(x) 824 # define CPL_LSBPTR32(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4) 826 # define CPL_MSBPTR32(x) CPL_SWAP32PTR(x) 828 # define CPL_LSBPTR64(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8) 830 # define CPL_MSBPTR64(x) CPL_SWAP64PTR(x) 836 #define CPL_LSBINT16PTR(x) ((*CPL_REINTERPRET_CAST(const GByte*, x)) | (*((CPL_REINTERPRET_CAST(const GByte*, x))+1) << 8)) 841 #define CPL_LSBINT32PTR(x) ((*CPL_REINTERPRET_CAST(const GByte*, x)) | (*((CPL_REINTERPRET_CAST(const GByte*, x))+1) << 8) | \ 842 (*((CPL_REINTERPRET_CAST(const GByte*, x))+2) << 16) | (*((CPL_REINTERPRET_CAST(const GByte*, x))+3) << 24)) 845 #define CPL_LSBSINT16PTR(x) CPL_STATIC_CAST(GInt16,CPL_LSBINT16PTR(x)) 848 #define CPL_LSBUINT16PTR(x) CPL_STATIC_CAST(GUInt16, CPL_LSBINT16PTR(x)) 851 #define CPL_LSBSINT32PTR(x) CPL_STATIC_CAST(GInt32, CPL_LSBINT32PTR(x)) 854 #define CPL_LSBUINT32PTR(x) CPL_STATIC_CAST(GUInt32, CPL_LSBINT32PTR(x)) 858 #ifndef UNREFERENCED_PARAM 859 # ifdef UNREFERENCED_PARAMETER 860 # define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param) 862 # define UNREFERENCED_PARAM(param) ((void)param) 876 #ifndef DISABLE_CVSID 877 #if defined(__GNUC__) && __GNUC__ >= 4 878 # define CPL_CVSID(string) static const char cpl_cvsid[] __attribute__((used)) = string; 880 # define CPL_CVSID(string) static const char cpl_cvsid[] = string; \ 881 static const char *cvsid_aw() { return( cvsid_aw() ? NULL : cpl_cvsid ); } 884 # define CPL_CVSID(string) 889 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) && !(defined(__MINGW64__) && __GNUC__ == 4 && __GNUC_MINOR__ == 6) 891 # define CPL_NULL_TERMINATED __attribute__((__sentinel__)) 894 # define CPL_NULL_TERMINATED 897 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP) 899 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx))) 901 #define CPL_SCAN_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__scanf__, format_idx, arg_idx))) 904 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx ) 906 #define CPL_SCAN_FUNC_FORMAT( format_idx, arg_idx ) 909 #if defined(_MSC_VER) && (defined(GDAL_COMPILATION) || defined(CPL_ENABLE_MSVC_ANNOTATIONS)) 913 # define CPL_FORMAT_STRING(arg) _Printf_format_string_ arg 916 # define CPL_SCANF_FORMAT_STRING(arg) _Scanf_format_string_ arg 919 # define CPL_FORMAT_STRING(arg) arg 921 # define CPL_SCANF_FORMAT_STRING(arg) arg 924 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) 926 #define CPL_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 929 #define CPL_WARN_UNUSED_RESULT 932 #if defined(__GNUC__) && __GNUC__ >= 4 934 # define CPL_UNUSED __attribute((__unused__)) 941 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP) 943 #define CPL_NO_RETURN __attribute__((noreturn)) 946 #define CPL_NO_RETURN 951 #ifndef __has_attribute 952 #define __has_attribute(x) 0 // Compatibility with non-clang compilers. 957 #if ((defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))) || __has_attribute(returns_nonnull)) && !defined(DOXYGEN_SKIP) && !defined(__INTEL_COMPILER) 959 # define CPL_RETURNS_NONNULL __attribute__((returns_nonnull)) 962 # define CPL_RETURNS_NONNULL 965 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) 967 #define CPL_RESTRICT __restrict__ 973 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) 977 # define CPL_OVERRIDE override 980 # define CPL_FINAL final 987 # define CPL_DISALLOW_COPY_ASSIGN(ClassName) \ 988 ClassName( const ClassName & ) = delete; \ 989 ClassName &operator=( const ClassName & ) = delete; 993 #if !defined(DOXYGEN_SKIP) 994 #if defined(__has_extension) 995 #if __has_extension(attribute_deprecated_with_message) 997 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated(x))) 999 #define CPL_WARN_DEPRECATED(x) 1001 #elif defined(__GNUC__) 1002 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated)) 1004 #define CPL_WARN_DEPRECATED(x) 1008 #if !defined(_MSC_VER) && !defined(__APPLE__) && !defined(_FORTIFY_SOURCE) 1010 # if defined(GDAL_COMPILATION) && defined(WARN_STANDARD_PRINTF) 1011 int vsnprintf(
char *str,
size_t size,
const char* fmt, va_list args)
1012 CPL_WARN_DEPRECATED(
"Use CPLvsnprintf() instead");
1013 int snprintf(
char *str,
size_t size,
const char* fmt, ...)
1016 int sprintf(
char *str, const
char* fmt, ...)
1019 # elif defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF) 1020 int sprintf(
char *str,
const char* fmt, ...)
1021 CPL_PRINT_FUNC_FORMAT(2, 3)
1022 CPL_WARN_DEPRECATED("Use snprintf() or
CPLsnprintf() instead");
1027 #if defined(MAKE_SANITIZE_HAPPY) || !(defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64)) 1029 #define CPL_CPU_REQUIRES_ALIGNED_ACCESS 1033 #if defined(__cplusplus) 1035 #define CPL_ARRAYSIZE(array) \ 1036 ((sizeof(array) / sizeof(*(array))) / \ 1037 static_cast<size_t>(!(sizeof(array) % sizeof(*(array))))) 1040 template<
class T>
static void CPL_IGNORE_RET_VAL(T) {}
1041 inline static bool CPL_TO_BOOL(
int x) {
return x != 0; }
1046 #if (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || (defined(__clang__) && __clang_major__ >= 3)) && !defined(_MSC_VER)) 1047 #define HAVE_GCC_DIAGNOSTIC_PUSH 1050 #if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) && !defined(_MSC_VER)) 1051 #define HAVE_GCC_SYSTEM_HEADER 1054 #if ((defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))) || __GNUC__ >= 7) 1056 # define CPL_FALLTHROUGH [[clang::fallthrough]]; 1059 # define CPL_FALLTHROUGH 1067 #if defined(__cplusplus) && defined(DEBUG_BOOL) && !defined(DO_NOT_USE_DEBUG_BOOL) && !defined(CPL_SUPRESS_CPLUSPLUS) 1069 class MSVCPedanticBool
1072 friend bool operator== (
const bool& one,
const MSVCPedanticBool& other);
1073 friend bool operator!= (
const bool& one,
const MSVCPedanticBool& other);
1076 MSVCPedanticBool(
int bIn);
1081 MSVCPedanticBool() {}
1082 MSVCPedanticBool(
bool bIn) : b(bIn) {}
1083 MSVCPedanticBool(
const MSVCPedanticBool& other) : b(other.b) {}
1085 MSVCPedanticBool& operator= (
const MSVCPedanticBool& other) { b = other.b;
return *
this; }
1086 MSVCPedanticBool& operator&= (
const MSVCPedanticBool& other) { b &= other.b;
return *
this; }
1087 MSVCPedanticBool& operator|= (
const MSVCPedanticBool& other) { b |= other.b;
return *
this; }
1089 bool operator== (
const bool& other)
const {
return b == other; }
1090 bool operator!= (
const bool& other)
const {
return b != other; }
1091 bool operator< (
const bool& other)
const {
return b < other; }
1092 bool operator== (
const MSVCPedanticBool& other)
const {
return b == other.b; }
1093 bool operator!= (
const MSVCPedanticBool& other)
const {
return b != other.b; }
1094 bool operator< (
const MSVCPedanticBool& other)
const {
return b < other.b; }
1096 bool operator! ()
const {
return !b; }
1097 operator bool()
const {
return b; }
1098 operator int()
const {
return b; }
1099 operator GIntBig()
const {
return b; }
1102 inline bool operator== (
const bool& one,
const MSVCPedanticBool& other) {
return one == other.b; }
1103 inline bool operator!= (
const bool& one,
const MSVCPedanticBool& other) {
return one != other.b; }
1114 #include <algorithm> 1115 #include <functional> 1119 #include <unordered_map> 1121 #include <unordered_set> 1133 #define EMULATED_BOOL int 1136 #define bool MSVCPedanticBool 1140 #define VOLATILE_BOOL bool 1152 #define EMULATED_BOOL bool 1153 #define VOLATILE_BOOL volatile bool 1157 #if __clang_major__ >= 4 || (__clang_major__ == 3 && __clang_minor__ >= 8) 1158 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW __attribute__((no_sanitize("unsigned-integer-overflow"))) 1160 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW 1165 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) 1166 #define CPL_NULLPTR nullptr 1168 #define CPL_NULLPTR NULL 1177 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && !defined(DOXYGEN_SKIP) #define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:335
int GBool
Type for boolean values (alias to int)
Definition: cpl_port.h:221
int GInt32
Int32 type.
Definition: cpl_port.h:203
unsigned int GUInt32
Unsigned int32 type.
Definition: cpl_port.h:205
short GInt16
Int16 type.
Definition: cpl_port.h:209
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:213
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:904
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition: cpl_port.h:267
GIntBig GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition: cpl_port.h:284
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1184
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:249
unsigned short GUInt16
Unsigned int16 type.
Definition: cpl_port.h:211
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
snprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1337
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:337
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:246
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:265