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(__MINGW32__) && __GNUC__ == 4 && __GNUC_MINOR__ == 2
660 static inline int CPLIsNan(
float f) {
return std::isnan(f); }
661 static inline int CPLIsNan(
double f) {
return std::isnan(f); }
662 static inline int CPLIsInf(
float f) {
return std::isinf(f); }
663 static inline int CPLIsInf(
double f) {
return std::isinf(f); }
664 static inline int CPLIsFinite(
float f) {
return std::isfinite(f); }
665 static inline int CPLIsFinite(
double f) {
return std::isfinite(f); }
667 #elif defined(__GNUC__) && ( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 4 ) )
670 # define CPLIsNan(x) __builtin_isnan(x)
671 # define CPLIsInf(x) __builtin_isinf(x)
672 # define CPLIsFinite(x) __builtin_isfinite(x)
675 #if defined(__cplusplus) && defined(__GNUC__) && defined(__linux) && !defined(__ANDROID__)
679 static inline int CPLIsNan(
float f) {
return __isnanf(f); }
680 static inline int CPLIsNan(
double f) {
return __isnan(f); }
681 static inline int CPLIsInf(
float f) {
return __isinff(f); }
682 static inline int CPLIsInf(
double f) {
return __isinf(f); }
683 static inline int CPLIsFinite(
float f) {
return !__isnanf(f) && !__isinff(f); }
684 static inline int CPLIsFinite(
double f) {
return !__isnan(f) && !__isinf(f); }
687 # define CPLIsNan(x) isnan(x)
688 # if defined(isinf) || defined(__FreeBSD__)
690 # define CPLIsInf(x) isinf(x)
692 # define CPLIsFinite(x) (!isnan(x) && !isinf(x))
693 # elif defined(__sun__)
695 # define CPLIsInf(x) (!finite(x) && !isnan(x))
696 # define CPLIsFinite(x) finite(x)
698 # define CPLIsInf(x) (0)
699 # define CPLIsFinite(x) (!isnan(x))
712 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
716 #if ! ( defined(CPL_LSB) || defined(CPL_MSB) )
721 # define CPL_IS_LSB 1
723 # define CPL_IS_LSB 0
732 template <
bool b>
struct CPLStaticAssert {};
733 template<>
struct CPLStaticAssert<true>
735 static void my_function() {}
740 #define CPL_STATIC_ASSERT(x) CPLStaticAssert<x>::my_function()
741 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x) CPL_STATIC_ASSERT(x)
745 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x)
755 #define CPL_SWAP16(x) ((GUInt16)( ((GUInt16)(x) << 8) | ((GUInt16)(x) >> 8) ))
757 #if defined(HAVE_GCC_BSWAP) && (defined(__i386__) || defined(__x86_64__))
761 #include <x86intrin.h>
763 #define CPL_SWAP32(x) ((GUInt32)(__builtin_bswap32((GUInt32)(x))))
765 #define CPL_SWAP64(x) ((GUInt64)(__builtin_bswap64((GUInt64)(x))))
766 #elif defined(_MSC_VER)
767 #define CPL_SWAP32(x) ((GUInt32)(_byteswap_ulong((GUInt32)(x))))
768 #define CPL_SWAP64(x) ((GUInt64)(_byteswap_uint64((GUInt64)(x))))
771 #define CPL_SWAP32(x) \
773 (((GUInt32)(x) & (GUInt32)0x000000ffUL) << 24) | \
774 (((GUInt32)(x) & (GUInt32)0x0000ff00UL) << 8) | \
775 (((GUInt32)(x) & (GUInt32)0x00ff0000UL) >> 8) | \
776 (((GUInt32)(x) & (GUInt32)0xff000000UL) >> 24) ))
779 #define CPL_SWAP64(x) \
780 (((GUInt64)(CPL_SWAP32((GUInt32)(x))) << 32) | \
781 (GUInt64)(CPL_SWAP32((GUInt32)((GUInt64)(x) >> 32))))
786 #define CPL_SWAP16PTR(x) \
788 GByte byTemp, *_pabyDataT = (GByte *) (x); \
789 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2); \
791 byTemp = _pabyDataT[0]; \
792 _pabyDataT[0] = _pabyDataT[1]; \
793 _pabyDataT[1] = byTemp; \
796 #if defined(MAKE_SANITIZE_HAPPY) || !(defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64))
799 #define CPL_SWAP32PTR(x) \
801 GByte byTemp, *_pabyDataT = (GByte *) (x); \
802 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4); \
804 byTemp = _pabyDataT[0]; \
805 _pabyDataT[0] = _pabyDataT[3]; \
806 _pabyDataT[3] = byTemp; \
807 byTemp = _pabyDataT[1]; \
808 _pabyDataT[1] = _pabyDataT[2]; \
809 _pabyDataT[2] = byTemp; \
813 #define CPL_SWAP64PTR(x) \
815 GByte byTemp, *_pabyDataT = (GByte *) (x); \
816 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8); \
818 byTemp = _pabyDataT[0]; \
819 _pabyDataT[0] = _pabyDataT[7]; \
820 _pabyDataT[7] = byTemp; \
821 byTemp = _pabyDataT[1]; \
822 _pabyDataT[1] = _pabyDataT[6]; \
823 _pabyDataT[6] = byTemp; \
824 byTemp = _pabyDataT[2]; \
825 _pabyDataT[2] = _pabyDataT[5]; \
826 _pabyDataT[5] = byTemp; \
827 byTemp = _pabyDataT[3]; \
828 _pabyDataT[3] = _pabyDataT[4]; \
829 _pabyDataT[4] = byTemp; \
835 #define CPL_SWAP32PTR(x) \
839 memcpy(&_n32, _lx, 4); \
840 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4); \
841 _n32 = CPL_SWAP32(_n32); \
842 memcpy(_lx, &_n32, 4); \
846 #define CPL_SWAP64PTR(x) \
850 memcpy(&_n64, _lx, 8); \
851 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8); \
852 _n64 = CPL_SWAP64(_n64); \
853 memcpy(_lx, &_n64, 8); \
859 #define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
862 # define CPL_MSBWORD16(x) (x)
863 # define CPL_LSBWORD16(x) CPL_SWAP16(x)
864 # define CPL_MSBWORD32(x) (x)
865 # define CPL_LSBWORD32(x) CPL_SWAP32(x)
866 # define CPL_MSBPTR16(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
867 # define CPL_LSBPTR16(x) CPL_SWAP16PTR(x)
868 # define CPL_MSBPTR32(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
869 # define CPL_LSBPTR32(x) CPL_SWAP32PTR(x)
870 # define CPL_MSBPTR64(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
871 # define CPL_LSBPTR64(x) CPL_SWAP64PTR(x)
874 # define CPL_LSBWORD16(x) (x)
876 # define CPL_MSBWORD16(x) CPL_SWAP16(x)
878 # define CPL_LSBWORD32(x) (x)
880 # define CPL_MSBWORD32(x) CPL_SWAP32(x)
882 # define CPL_LSBPTR16(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
884 # define CPL_MSBPTR16(x) CPL_SWAP16PTR(x)
886 # define CPL_LSBPTR32(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
888 # define CPL_MSBPTR32(x) CPL_SWAP32PTR(x)
890 # define CPL_LSBPTR64(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
892 # define CPL_MSBPTR64(x) CPL_SWAP64PTR(x)
898 #define CPL_LSBINT16PTR(x) ((*(GByte*)(x)) | (*(((GByte*)(x))+1) << 8))
903 #define CPL_LSBINT32PTR(x) ((*(GByte*)(x)) | (*(((GByte*)(x))+1) << 8) | \
904 (*(((GByte*)(x))+2) << 16) | (*(((GByte*)(x))+3) << 24))
907 #define CPL_LSBSINT16PTR(x) ((GInt16) CPL_LSBINT16PTR(x))
910 #define CPL_LSBUINT16PTR(x) ((GUInt16)CPL_LSBINT16PTR(x))
913 #define CPL_LSBSINT32PTR(x) ((GInt32) CPL_LSBINT32PTR(x))
916 #define CPL_LSBUINT32PTR(x) ((GUInt32)CPL_LSBINT32PTR(x))
920 #ifndef UNREFERENCED_PARAM
921 # ifdef UNREFERENCED_PARAMETER
922 # define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param)
924 # define UNREFERENCED_PARAM(param) ((void)param)
938 #ifndef DISABLE_CVSID
939 #if defined(__GNUC__) && __GNUC__ >= 4
940 # define CPL_CVSID(string) static const char cpl_cvsid[] __attribute__((used)) = string;
942 # define CPL_CVSID(string) static const char cpl_cvsid[] = string; \
943 static const char *cvsid_aw() { return( cvsid_aw() ? NULL : cpl_cvsid ); }
946 # define CPL_CVSID(string)
951 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) && !(defined(__MINGW64__) && __GNUC__ == 4 && __GNUC_MINOR__ == 6)
953 # define CPL_NULL_TERMINATED __attribute__((__sentinel__))
956 # define CPL_NULL_TERMINATED
959 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
961 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx)))
963 #define CPL_SCAN_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
966 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx )
968 #define CPL_SCAN_FUNC_FORMAT( format_idx, arg_idx )
971 #if defined(_MSC_VER) && _MSC_VER >= 1400 && (defined(GDAL_COMPILATION) || defined(CPL_ENABLE_MSVC_ANNOTATIONS))
976 # define CPL_FORMAT_STRING(arg) _Printf_format_string_ arg
979 # define CPL_SCANF_FORMAT_STRING(arg) _Scanf_format_string_ arg
982 # define CPL_FORMAT_STRING(arg) __format_string arg
984 # define CPL_SCANF_FORMAT_STRING(arg) arg
988 # define CPL_FORMAT_STRING(arg) arg
990 # define CPL_SCANF_FORMAT_STRING(arg) arg
993 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
995 #define CPL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
998 #define CPL_WARN_UNUSED_RESULT
1001 #if defined(__GNUC__) && __GNUC__ >= 4
1003 # define CPL_UNUSED __attribute((__unused__))
1010 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
1012 #define CPL_NO_RETURN __attribute__((noreturn))
1015 #define CPL_NO_RETURN
1020 #ifndef __has_attribute
1021 #define __has_attribute(x) 0 // Compatibility with non-clang compilers.
1026 #if ((defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))) || __has_attribute(returns_nonnull)) && !defined(DOXYGEN_SKIP) && !defined(__INTEL_COMPILER)
1028 # define CPL_RETURNS_NONNULL __attribute__((returns_nonnull))
1031 # define CPL_RETURNS_NONNULL
1034 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
1036 #define CPL_RESTRICT __restrict__
1039 #define CPL_RESTRICT
1044 #if HAVE_CXX11 || _MSC_VER >= 1500
1048 # define CPL_OVERRIDE override
1054 # define CPL_OVERRIDE
1057 #ifdef GDAL_COMPILATION
1065 # define CPL_FINAL final
1072 # define CPL_DISALLOW_COPY_ASSIGN(ClassName) \
1073 ClassName( const ClassName & ) = delete; \
1074 ClassName &operator=( const ClassName & ) = delete;
1084 # define CPL_DISALLOW_COPY_ASSIGN(ClassName) \
1085 ClassName( const ClassName & ); \
1086 ClassName &operator=( const ClassName & );
1091 #if !defined(DOXYGEN_SKIP)
1092 #if defined(__has_extension)
1093 #if __has_extension(attribute_deprecated_with_message)
1095 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated(x)))
1097 #define CPL_WARN_DEPRECATED(x)
1099 #elif defined(__GNUC__)
1100 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated))
1102 #define CPL_WARN_DEPRECATED(x)
1106 #if !defined(_MSC_VER) && !defined(__APPLE__) && !defined(_FORTIFY_SOURCE)
1108 # if defined(GDAL_COMPILATION) && defined(WARN_STANDARD_PRINTF)
1109 int vsnprintf(
char *str,
size_t size,
const char* fmt, va_list args)
1110 CPL_WARN_DEPRECATED(
"Use CPLvsnprintf() instead");
1111 int snprintf(
char *str,
size_t size,
const char* fmt, ...)
1114 int sprintf(
char *str, const
char* fmt, ...)
1117 # elif defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
1118 int sprintf(
char *str,
const char* fmt, ...)
1119 CPL_PRINT_FUNC_FORMAT(2, 3)
1120 CPL_WARN_DEPRECATED("Use snprintf() or
CPLsnprintf() instead");
1125 #if defined(MAKE_SANITIZE_HAPPY) || !(defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64))
1127 #define CPL_CPU_REQUIRES_ALIGNED_ACCESS
1133 #define CPL_ARRAYSIZE(array) \
1134 ((sizeof(array) / sizeof(*(array))) / \
1135 static_cast<size_t>(!(sizeof(array) % sizeof(*(array)))))
1138 template<
class T>
static void CPL_IGNORE_RET_VAL(T) {}
1139 inline static bool CPL_TO_BOOL(
int x) {
return x != 0; }
1144 #if (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || (defined(__clang__) && __clang_major__ >= 3)) && !defined(_MSC_VER))
1145 #define HAVE_GCC_DIAGNOSTIC_PUSH
1148 #if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) && !defined(_MSC_VER))
1149 #define HAVE_GCC_SYSTEM_HEADER
1152 #if ((defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))) || __GNUC__ >= 7) && HAVE_CXX11
1154 # define CPL_FALLTHROUGH [[clang::fallthrough]];
1157 # define CPL_FALLTHROUGH
1165 #if defined(__cplusplus) && defined(DEBUG_BOOL) && !defined(DO_NOT_USE_DEBUG_BOOL)
1167 class MSVCPedanticBool
1170 friend bool operator== (
const bool& one,
const MSVCPedanticBool& other);
1171 friend bool operator!= (
const bool& one,
const MSVCPedanticBool& other);
1174 MSVCPedanticBool(
int bIn);
1179 MSVCPedanticBool() {}
1180 MSVCPedanticBool(
bool bIn) : b(bIn) {}
1181 MSVCPedanticBool(
const MSVCPedanticBool& other) : b(other.b) {}
1183 MSVCPedanticBool& operator= (
const MSVCPedanticBool& other) { b = other.b;
return *
this; }
1184 MSVCPedanticBool& operator&= (
const MSVCPedanticBool& other) { b &= other.b;
return *
this; }
1185 MSVCPedanticBool& operator|= (
const MSVCPedanticBool& other) { b |= other.b;
return *
this; }
1187 bool operator== (
const bool& other)
const {
return b == other; }
1188 bool operator!= (
const bool& other)
const {
return b != other; }
1189 bool operator== (
const MSVCPedanticBool& other)
const {
return b == other.b; }
1190 bool operator!= (
const MSVCPedanticBool& other)
const {
return b != other.b; }
1192 bool operator! ()
const {
return !b; }
1193 operator bool()
const {
return b; }
1194 operator int()
const {
return b; }
1197 inline bool operator== (
const bool& one,
const MSVCPedanticBool& other) {
return one == other.b; }
1198 inline bool operator!= (
const bool& one,
const MSVCPedanticBool& other) {
return one != other.b; }
1209 #include <algorithm>
1219 #define EMULATED_BOOL int
1222 #define bool MSVCPedanticBool
1226 #define VOLATILE_BOOL bool
1238 #define EMULATED_BOOL bool
1239 #define VOLATILE_BOOL volatile bool
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:352
int GBool
Type for boolean values (alias to int)
Definition: cpl_port.h:215
int GInt32
Int32 type.
Definition: cpl_port.h:197
unsigned int GUInt32
Unsigned int32 type.
Definition: cpl_port.h:199
short GInt16
Int16 type.
Definition: cpl_port.h:203
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:207
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:966
#define CPLIsNan(x)
Return whether a floating-pointer number is NaN.
Definition: cpl_port.h:687
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition: cpl_port.h:271
GIntBig GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition: cpl_port.h:294
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:253
unsigned short GUInt16
Unsigned int16 type.
Definition: cpl_port.h:205
#define CPLIsInf(x)
Return whether a floating-pointer number is +/- infinty.
Definition: cpl_port.h:690
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
snprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1329
#define CPLIsFinite(x)
Return whether a floating-pointer number is finite.
Definition: cpl_port.h:692
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:354
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:250
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:269