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>
183 # if __cplusplus >= 201103L
184 # define HAVE_CXX11 1
192 #if UINT_MAX == 65535
210 #ifndef CPL_GBOOL_DEFINED
212 #define CPL_GBOOL_DEFINED
222 #if defined(WIN32) && defined(_MSC_VER)
224 #define VSI_LARGE_API_SUPPORTED
229 #define GINTBIG_MIN ((GIntBig)(0x80000000) << 32)
231 #define GINTBIG_MAX (((GIntBig)(0x7FFFFFFF) << 32) | 0xFFFFFFFFU)
233 #define GUINTBIG_MAX (((GUIntBig)(0xFFFFFFFFU) << 32) | 0xFFFFFFFFU)
235 #define CPL_HAS_GINT64 1
242 #define GINT64_MIN GINTBIG_MIN
243 #define GINT64_MAX GINTBIG_MAX
244 #define GUINT64_MAX GUINTBIG_MAX
256 #define GINTBIG_MIN ((GIntBig)(0x80000000) << 32)
258 #define GINTBIG_MAX (((GIntBig)(0x7FFFFFFF) << 32) | 0xFFFFFFFFU)
260 #define GUINTBIG_MAX (((GUIntBig)(0xFFFFFFFFU) << 32) | 0xFFFFFFFFU)
263 #define CPL_HAS_GINT64 1
274 #define GINT64_MIN GINTBIG_MIN
276 #define GINT64_MAX GINTBIG_MAX
278 #define GUINT64_MAX GUINTBIG_MAX
287 #define GINTBIG_MIN INT_MIN
288 #define GINTBIG_MAX INT_MAX
289 #define GUINTBIG_MAX UINT_MAX
292 #if SIZEOF_VOIDP == 8
300 #ifdef GDAL_COMPILATION
302 #if !defined(_MSC_VER) || _MSC_VER > 1500
305 typedef uintptr_t GUIntptr_t;
306 #elif SIZEOF_VOIDP == 8
309 typedef unsigned int GUIntptr_t;
312 #define CPL_IS_ALIGNED(ptr, quant) (((GUIntptr_t)(ptr) % (quant)) == 0)
316 #if defined(__MSVCRT__) || (defined(WIN32) && defined(_MSC_VER))
317 #define CPL_FRMT_GB_WITHOUT_PREFIX "I64"
320 #define CPL_FRMT_GB_WITHOUT_PREFIX "ll"
322 #define CPL_FRMT_GB_WITHOUT_PREFIX "l"
326 #define CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"
328 #define CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"
332 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
333 #define GUINTBIG_TO_DOUBLE(x) (double)(GIntBig)(x)
335 #define GUINTBIG_TO_DOUBLE(x) (double)(x)
340 #ifdef COMPAT_WITH_ICC_CONVERSION_CHECK
341 #define CPL_INT64_FITS_ON_INT32(x) ((x) >= INT_MIN && (x) <= INT_MAX)
343 #define CPL_INT64_FITS_ON_INT32(x) (((GIntBig)(int)(x)) == (x))
352 # define CPL_C_START extern "C" {
361 #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
362 # define CPL_DLL __declspec(dllexport)
364 # if defined(USE_GCC_VISIBILITY_FLAG)
365 # define CPL_DLL __attribute__ ((visibility("default")))
374 #ifdef CPL_OPTIONAL_APIS
375 # define CPL_ODLL CPL_DLL
382 #if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL)
383 # define CPL_STDCALL __stdcall
391 # define FORCE_CDECL __cdecl
399 #if (defined(__GNUC__) && !defined(__NO_INLINE__)) || defined(_MSC_VER)
400 #define HAS_CPL_INLINE 1
401 #define CPL_INLINE __inline
402 #elif defined(__SUNPRO_CC)
403 #define HAS_CPL_INLINE 1
404 #define CPL_INLINE inline
413 #if defined(NULL_AS_NULLPTR) && HAVE_CXX11
421 #include <sys/types.h>
426 #include <sys/mman.h>
458 # define MIN(a,b) (((a)<(b)) ? (a) : (b))
460 # define MAX(a,b) (((a)>(b)) ? (a) : (b))
465 # define ABS(x) (((x)<0) ? (-1*(x)) : (x))
470 # define M_PI 3.14159265358979323846
481 # define CPLIsEqual(x,y) (fabs((x) - (y)) < 0.0000000000001)
490 #if defined(AFL_FRIENDLY) && defined(__GNUC__)
492 static inline int CPL_afl_friendly_memcmp(
const void* ptr1,
const void* ptr2,
size_t len)
493 __attribute__((always_inline));
495 static inline int CPL_afl_friendly_memcmp(
const void* ptr1,
const void* ptr2,
size_t len)
497 const unsigned char* bptr1 = (
const unsigned char*)ptr1;
498 const unsigned char* bptr2 = (
const unsigned char*)ptr2;
501 unsigned char b1 = *(bptr1++);
502 unsigned char b2 = *(bptr2++);
503 if( b1 != b2 )
return b1 - b2;
508 static inline int CPL_afl_friendly_strcmp(
const char* ptr1,
const char* ptr2)
509 __attribute__((always_inline));
511 static inline int CPL_afl_friendly_strcmp(
const char* ptr1,
const char* ptr2)
513 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
514 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
517 unsigned char ch1 = *(usptr1++);
518 unsigned char ch2 = *(usptr2++);
519 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
523 static inline int CPL_afl_friendly_strncmp(
const char* ptr1,
const char* ptr2,
size_t len)
524 __attribute__((always_inline));
526 static inline int CPL_afl_friendly_strncmp(
const char* ptr1,
const char* ptr2,
size_t len)
528 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
529 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
532 unsigned char ch1 = *(usptr1++);
533 unsigned char ch2 = *(usptr2++);
534 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
539 static inline int CPL_afl_friendly_strcasecmp(
const char* ptr1,
const char* ptr2)
540 __attribute__((always_inline));
542 static inline int CPL_afl_friendly_strcasecmp(
const char* ptr1,
const char* ptr2)
544 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
545 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
548 unsigned char ch1 = *(usptr1++);
549 unsigned char ch2 = *(usptr2++);
550 ch1 = (
unsigned char)toupper(ch1);
551 ch2 = (
unsigned char)toupper(ch2);
552 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
556 static inline int CPL_afl_friendly_strncasecmp(
const char* ptr1,
const char* ptr2,
size_t len)
557 __attribute__((always_inline));
559 static inline int CPL_afl_friendly_strncasecmp(
const char* ptr1,
const char* ptr2,
size_t len)
561 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
562 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
565 unsigned char ch1 = *(usptr1++);
566 unsigned char ch2 = *(usptr2++);
567 ch1 = (
unsigned char)toupper(ch1);
568 ch2 = (
unsigned char)toupper(ch2);
569 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
574 static inline char* CPL_afl_friendly_strstr(
const char* haystack,
const char* needle)
575 __attribute__((always_inline));
577 static inline char* CPL_afl_friendly_strstr(
const char* haystack,
const char* needle)
579 const char* ptr_haystack = haystack;
582 const char* ptr_haystack2 = ptr_haystack;
583 const char* ptr_needle = needle;
586 char ch1 = *(ptr_haystack2++);
587 char ch2 = *(ptr_needle++);
589 return (
char*)ptr_haystack;
593 if( *ptr_haystack == 0 )
601 #define memcmp CPL_afl_friendly_memcmp
602 #define strcmp CPL_afl_friendly_strcmp
603 #define strncmp CPL_afl_friendly_strncmp
604 #define strcasecmp CPL_afl_friendly_strcasecmp
605 #define strncasecmp CPL_afl_friendly_strncasecmp
606 #define strstr CPL_afl_friendly_strstr
611 # define STRCASECMP(a,b) (stricmp(a,b))
612 # define STRNCASECMP(a,b,n) (strnicmp(a,b,n))
615 # define STRCASECMP(a,b) (strcasecmp(a,b))
617 # define STRNCASECMP(a,b,n) (strncasecmp(a,b,n))
620 # define EQUALN(a,b,n) (STRNCASECMP(a,b,n)==0)
622 # define EQUAL(a,b) (STRCASECMP(a,b)==0)
629 #ifndef STARTS_WITH_CI
631 #define STARTS_WITH(a,b) (strncmp(a,b,strlen(b)) == 0)
633 #define STARTS_WITH_CI(a,b) EQUALN(a,b,strlen(b))
637 #ifndef CPL_THREADLOCAL
638 # define CPL_THREADLOCAL
653 # define CPLIsNan(x) _isnan(x)
654 # define CPLIsInf(x) (!_isnan(x) && !_finite(x))
655 # define CPLIsFinite(x) _finite(x)
656 #elif defined(__cplusplus) && defined(HAVE_STD_IS_NAN) && HAVE_STD_IS_NAN
661 static inline int CPLIsNan(
float f) {
return std::isnan(f); }
662 static inline int CPLIsNan(
double f) {
return std::isnan(f); }
663 static inline int CPLIsInf(
float f) {
return std::isinf(f); }
664 static inline int CPLIsInf(
double f) {
return std::isinf(f); }
665 static inline int CPLIsFinite(
float f) {
return std::isfinite(f); }
666 static inline int CPLIsFinite(
double f) {
return std::isfinite(f); }
668 #elif defined(__GNUC__) && ( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 4 ) )
671 # define CPLIsNan(x) __builtin_isnan(x)
672 # define CPLIsInf(x) __builtin_isinf(x)
673 # define CPLIsFinite(x) __builtin_isfinite(x)
676 #if defined(__cplusplus) && defined(__GNUC__) && defined(__linux) && !defined(__ANDROID__)
680 static inline int CPLIsNan(
float f) {
return __isnanf(f); }
681 static inline int CPLIsNan(
double f) {
return __isnan(f); }
682 static inline int CPLIsInf(
float f) {
return __isinff(f); }
683 static inline int CPLIsInf(
double f) {
return __isinf(f); }
684 static inline int CPLIsFinite(
float f) {
return !__isnanf(f) && !__isinff(f); }
685 static inline int CPLIsFinite(
double f) {
return !__isnan(f) && !__isinf(f); }
688 # define CPLIsNan(x) isnan(x)
689 # if defined(isinf) || defined(__FreeBSD__)
691 # define CPLIsInf(x) isinf(x)
693 # define CPLIsFinite(x) (!isnan(x) && !isinf(x))
694 # elif defined(__sun__)
696 # define CPLIsInf(x) (!finite(x) && !isnan(x))
697 # define CPLIsFinite(x) finite(x)
699 # define CPLIsInf(x) (0)
700 # define CPLIsFinite(x) (!isnan(x))
713 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
717 #if ! ( defined(CPL_LSB) || defined(CPL_MSB) )
722 # define CPL_IS_LSB 1
724 # define CPL_IS_LSB 0
733 template <
bool b>
struct CPLStaticAssert {};
734 template<>
struct CPLStaticAssert<true>
736 static void my_function() {}
741 #define CPL_STATIC_ASSERT(x) CPLStaticAssert<x>::my_function()
742 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x) CPL_STATIC_ASSERT(x)
746 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x)
756 #define CPL_SWAP16(x) ((GUInt16)( ((GUInt16)(x) << 8) | ((GUInt16)(x) >> 8) ))
758 #if defined(HAVE_GCC_BSWAP) && (defined(__i386__) || defined(__x86_64__))
762 #include <x86intrin.h>
764 #define CPL_SWAP32(x) ((GUInt32)(__builtin_bswap32((GUInt32)(x))))
766 #define CPL_SWAP64(x) ((GUInt64)(__builtin_bswap64((GUInt64)(x))))
767 #elif defined(_MSC_VER)
768 #define CPL_SWAP32(x) ((GUInt32)(_byteswap_ulong((GUInt32)(x))))
769 #define CPL_SWAP64(x) ((GUInt64)(_byteswap_uint64((GUInt64)(x))))
772 #define CPL_SWAP32(x) \
774 (((GUInt32)(x) & (GUInt32)0x000000ffUL) << 24) | \
775 (((GUInt32)(x) & (GUInt32)0x0000ff00UL) << 8) | \
776 (((GUInt32)(x) & (GUInt32)0x00ff0000UL) >> 8) | \
777 (((GUInt32)(x) & (GUInt32)0xff000000UL) >> 24) ))
780 #define CPL_SWAP64(x) \
781 (((GUInt64)(CPL_SWAP32((GUInt32)(x))) << 32) | \
782 (GUInt64)(CPL_SWAP32((GUInt32)((GUInt64)(x) >> 32))))
787 #define CPL_SWAP16PTR(x) \
789 GByte byTemp, *_pabyDataT = (GByte *) (x); \
790 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2); \
792 byTemp = _pabyDataT[0]; \
793 _pabyDataT[0] = _pabyDataT[1]; \
794 _pabyDataT[1] = byTemp; \
797 #if defined(MAKE_SANITIZE_HAPPY) || !(defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64))
800 #define CPL_SWAP32PTR(x) \
802 GByte byTemp, *_pabyDataT = (GByte *) (x); \
803 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4); \
805 byTemp = _pabyDataT[0]; \
806 _pabyDataT[0] = _pabyDataT[3]; \
807 _pabyDataT[3] = byTemp; \
808 byTemp = _pabyDataT[1]; \
809 _pabyDataT[1] = _pabyDataT[2]; \
810 _pabyDataT[2] = byTemp; \
814 #define CPL_SWAP64PTR(x) \
816 GByte byTemp, *_pabyDataT = (GByte *) (x); \
817 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8); \
819 byTemp = _pabyDataT[0]; \
820 _pabyDataT[0] = _pabyDataT[7]; \
821 _pabyDataT[7] = byTemp; \
822 byTemp = _pabyDataT[1]; \
823 _pabyDataT[1] = _pabyDataT[6]; \
824 _pabyDataT[6] = byTemp; \
825 byTemp = _pabyDataT[2]; \
826 _pabyDataT[2] = _pabyDataT[5]; \
827 _pabyDataT[5] = byTemp; \
828 byTemp = _pabyDataT[3]; \
829 _pabyDataT[3] = _pabyDataT[4]; \
830 _pabyDataT[4] = byTemp; \
836 #define CPL_SWAP32PTR(x) \
840 memcpy(&_n32, _lx, 4); \
841 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4); \
842 _n32 = CPL_SWAP32(_n32); \
843 memcpy(_lx, &_n32, 4); \
847 #define CPL_SWAP64PTR(x) \
851 memcpy(&_n64, _lx, 8); \
852 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8); \
853 _n64 = CPL_SWAP64(_n64); \
854 memcpy(_lx, &_n64, 8); \
860 #define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
863 # define CPL_MSBWORD16(x) (x)
864 # define CPL_LSBWORD16(x) CPL_SWAP16(x)
865 # define CPL_MSBWORD32(x) (x)
866 # define CPL_LSBWORD32(x) CPL_SWAP32(x)
867 # define CPL_MSBPTR16(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
868 # define CPL_LSBPTR16(x) CPL_SWAP16PTR(x)
869 # define CPL_MSBPTR32(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
870 # define CPL_LSBPTR32(x) CPL_SWAP32PTR(x)
871 # define CPL_MSBPTR64(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
872 # define CPL_LSBPTR64(x) CPL_SWAP64PTR(x)
875 # define CPL_LSBWORD16(x) (x)
877 # define CPL_MSBWORD16(x) CPL_SWAP16(x)
879 # define CPL_LSBWORD32(x) (x)
881 # define CPL_MSBWORD32(x) CPL_SWAP32(x)
883 # define CPL_LSBPTR16(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
885 # define CPL_MSBPTR16(x) CPL_SWAP16PTR(x)
887 # define CPL_LSBPTR32(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
889 # define CPL_MSBPTR32(x) CPL_SWAP32PTR(x)
891 # define CPL_LSBPTR64(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
893 # define CPL_MSBPTR64(x) CPL_SWAP64PTR(x)
899 #define CPL_LSBINT16PTR(x) ((*(GByte*)(x)) | (*(((GByte*)(x))+1) << 8))
904 #define CPL_LSBINT32PTR(x) ((*(GByte*)(x)) | (*(((GByte*)(x))+1) << 8) | \
905 (*(((GByte*)(x))+2) << 16) | (*(((GByte*)(x))+3) << 24))
908 #define CPL_LSBSINT16PTR(x) ((GInt16) CPL_LSBINT16PTR(x))
911 #define CPL_LSBUINT16PTR(x) ((GUInt16)CPL_LSBINT16PTR(x))
914 #define CPL_LSBSINT32PTR(x) ((GInt32) CPL_LSBINT32PTR(x))
917 #define CPL_LSBUINT32PTR(x) ((GUInt32)CPL_LSBINT32PTR(x))
921 #ifndef UNREFERENCED_PARAM
922 # ifdef UNREFERENCED_PARAMETER
923 # define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param)
925 # define UNREFERENCED_PARAM(param) ((void)param)
939 #ifndef DISABLE_CVSID
940 #if defined(__GNUC__) && __GNUC__ >= 4
941 # define CPL_CVSID(string) static const char cpl_cvsid[] __attribute__((used)) = string;
943 # define CPL_CVSID(string) static const char cpl_cvsid[] = string; \
944 static const char *cvsid_aw() { return( cvsid_aw() ? NULL : cpl_cvsid ); }
947 # define CPL_CVSID(string)
952 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) && !(defined(__MINGW64__) && __GNUC__ == 4 && __GNUC_MINOR__ == 6)
954 # define CPL_NULL_TERMINATED __attribute__((__sentinel__))
957 # define CPL_NULL_TERMINATED
960 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
962 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx)))
964 #define CPL_SCAN_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
967 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx )
969 #define CPL_SCAN_FUNC_FORMAT( format_idx, arg_idx )
972 #if defined(_MSC_VER) && _MSC_VER >= 1400 && (defined(GDAL_COMPILATION) || defined(CPL_ENABLE_MSVC_ANNOTATIONS))
977 # define CPL_FORMAT_STRING(arg) _Printf_format_string_ arg
980 # define CPL_SCANF_FORMAT_STRING(arg) _Scanf_format_string_ arg
983 # define CPL_FORMAT_STRING(arg) __format_string arg
985 # define CPL_SCANF_FORMAT_STRING(arg) arg
989 # define CPL_FORMAT_STRING(arg) arg
991 # define CPL_SCANF_FORMAT_STRING(arg) arg
994 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
996 #define CPL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
999 #define CPL_WARN_UNUSED_RESULT
1002 #if defined(__GNUC__) && __GNUC__ >= 4
1004 # define CPL_UNUSED __attribute((__unused__))
1011 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
1013 #define CPL_NO_RETURN __attribute__((noreturn))
1016 #define CPL_NO_RETURN
1021 #ifndef __has_attribute
1022 #define __has_attribute(x) 0 // Compatibility with non-clang compilers.
1027 #if ((defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))) || __has_attribute(returns_nonnull)) && !defined(DOXYGEN_SKIP) && !defined(__INTEL_COMPILER)
1029 # define CPL_RETURNS_NONNULL __attribute__((returns_nonnull))
1032 # define CPL_RETURNS_NONNULL
1035 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
1037 #define CPL_RESTRICT __restrict__
1040 #define CPL_RESTRICT
1045 #if HAVE_CXX11 || _MSC_VER >= 1500
1049 # define CPL_OVERRIDE override
1055 # define CPL_OVERRIDE
1058 #ifdef GDAL_COMPILATION
1066 # define CPL_FINAL final
1073 # define CPL_DISALLOW_COPY_ASSIGN(ClassName) \
1074 ClassName( const ClassName & ) = delete; \
1075 ClassName &operator=( const ClassName & ) = delete;
1085 # define CPL_DISALLOW_COPY_ASSIGN(ClassName) \
1086 ClassName( const ClassName & ); \
1087 ClassName &operator=( const ClassName & );
1092 #if !defined(DOXYGEN_SKIP)
1093 #if defined(__has_extension)
1094 #if __has_extension(attribute_deprecated_with_message)
1096 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated(x)))
1098 #define CPL_WARN_DEPRECATED(x)
1100 #elif defined(__GNUC__)
1101 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated))
1103 #define CPL_WARN_DEPRECATED(x)
1107 #if !defined(_MSC_VER) && !defined(__APPLE__) && !defined(_FORTIFY_SOURCE)
1109 # if defined(GDAL_COMPILATION) && defined(WARN_STANDARD_PRINTF)
1110 int vsnprintf(
char *str,
size_t size,
const char* fmt, va_list args)
1111 CPL_WARN_DEPRECATED(
"Use CPLvsnprintf() instead");
1112 int snprintf(
char *str,
size_t size,
const char* fmt, ...)
1115 int sprintf(
char *str, const
char* fmt, ...)
1118 # elif defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
1119 int sprintf(
char *str,
const char* fmt, ...)
1120 CPL_PRINT_FUNC_FORMAT(2, 3)
1121 CPL_WARN_DEPRECATED("Use snprintf() or
CPLsnprintf() instead");
1126 #if defined(MAKE_SANITIZE_HAPPY) || !(defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64))
1128 #define CPL_CPU_REQUIRES_ALIGNED_ACCESS
1134 #define CPL_ARRAYSIZE(array) \
1135 ((sizeof(array) / sizeof(*(array))) / \
1136 static_cast<size_t>(!(sizeof(array) % sizeof(*(array)))))
1139 template<
class T>
static void CPL_IGNORE_RET_VAL(T) {}
1140 inline static bool CPL_TO_BOOL(
int x) {
return x != 0; }
1145 #if (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || (defined(__clang__) && __clang_major__ >= 3)) && !defined(_MSC_VER))
1146 #define HAVE_GCC_DIAGNOSTIC_PUSH
1149 #if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) && !defined(_MSC_VER))
1150 #define HAVE_GCC_SYSTEM_HEADER
1153 #if ((defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))) || __GNUC__ >= 7) && HAVE_CXX11
1155 # define CPL_FALLTHROUGH [[clang::fallthrough]];
1158 # define CPL_FALLTHROUGH
1166 #if defined(__cplusplus) && defined(DEBUG_BOOL) && !defined(DO_NOT_USE_DEBUG_BOOL)
1168 class MSVCPedanticBool
1171 friend bool operator== (
const bool& one,
const MSVCPedanticBool& other);
1172 friend bool operator!= (
const bool& one,
const MSVCPedanticBool& other);
1175 MSVCPedanticBool(
int bIn);
1180 MSVCPedanticBool() {}
1181 MSVCPedanticBool(
bool bIn) : b(bIn) {}
1182 MSVCPedanticBool(
const MSVCPedanticBool& other) : b(other.b) {}
1184 MSVCPedanticBool& operator= (
const MSVCPedanticBool& other) { b = other.b;
return *
this; }
1185 MSVCPedanticBool& operator&= (
const MSVCPedanticBool& other) { b &= other.b;
return *
this; }
1186 MSVCPedanticBool& operator|= (
const MSVCPedanticBool& other) { b |= other.b;
return *
this; }
1188 bool operator== (
const bool& other)
const {
return b == other; }
1189 bool operator!= (
const bool& other)
const {
return b != other; }
1190 bool operator== (
const MSVCPedanticBool& other)
const {
return b == other.b; }
1191 bool operator!= (
const MSVCPedanticBool& other)
const {
return b != other.b; }
1193 bool operator! ()
const {
return !b; }
1194 operator bool()
const {
return b; }
1195 operator int()
const {
return b; }
1198 inline bool operator== (
const bool& one,
const MSVCPedanticBool& other) {
return one == other.b; }
1199 inline bool operator!= (
const bool& one,
const MSVCPedanticBool& other) {
return one != other.b; }
1210 #include <algorithm>
1220 #define EMULATED_BOOL int
1223 #define bool MSVCPedanticBool
1227 #define VOLATILE_BOOL bool
1239 #define EMULATED_BOOL bool
1240 #define VOLATILE_BOOL volatile bool
#define CPL_C_START
Definition: cpl_port.h:352
int GBool
Definition: cpl_port.h:215
int GInt32
Definition: cpl_port.h:197
unsigned int GUInt32
Definition: cpl_port.h:199
short GInt16
Definition: cpl_port.h:203
unsigned char GByte
Definition: cpl_port.h:207
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Definition: cpl_port.h:967
GUIntBig GUInt64
Definition: cpl_port.h:271
GIntBig GPtrDiff_t
Definition: cpl_port.h:294
unsigned long long GUIntBig
Definition: cpl_port.h:253
unsigned short GUInt16
Definition: cpl_port.h:205
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
Definition: cpl_string.cpp:1333
#define CPL_C_END
Definition: cpl_port.h:354
long long GIntBig
Definition: cpl_port.h:250
GIntBig GInt64
Definition: cpl_port.h:269