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__ + 0) >= 201112L && (_XOPEN_SOURCE + 0) < 600
130 #define _XOPEN_SOURCE 600
158 # include <strings.h>
173 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
174 # if !(__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900))
175 # error Must have C++11 or newer.
177 # if __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
178 # define HAVE_CXX14 1
180 # if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
181 # define HAVE_CXX17 1
188 #if UINT_MAX == 65535
206 #ifndef CPL_GBOOL_DEFINED
208 #define CPL_GBOOL_DEFINED
216 #define CPL_STATIC_CAST(type, expr) static_cast<type>(expr)
217 #define CPL_REINTERPRET_CAST(type, expr) reinterpret_cast<type>(expr)
219 #define CPL_STATIC_CAST(type, expr) ((type)(expr))
220 #define CPL_REINTERPRET_CAST(type, expr) ((type)(expr))
236 #define GINTBIG_MIN (CPL_STATIC_CAST(GIntBig, 0x80000000) << 32)
238 #define GINTBIG_MAX ((CPL_STATIC_CAST(GIntBig, 0x7FFFFFFF) << 32) | 0xFFFFFFFFU)
240 #define GUINTBIG_MAX ((CPL_STATIC_CAST(GUIntBig, 0xFFFFFFFFU) << 32) | 0xFFFFFFFFU)
243 #define CPL_HAS_GINT64 1
254 #define GINT64_MIN GINTBIG_MIN
256 #define GINT64_MAX GINTBIG_MAX
258 #define GUINT64_MAX GUINTBIG_MAX
261 #if SIZEOF_VOIDP == 8
269 #ifdef GDAL_COMPILATION
271 typedef uintptr_t GUIntptr_t;
272 #define CPL_IS_ALIGNED(ptr, quant) ((CPL_REINTERPRET_CAST(GUIntptr_t, CPL_STATIC_CAST(const void*, ptr)) % (quant)) == 0)
276 #if (defined(__MSVCRT__) && !(defined(__MINGW64__) && __GNUC__ >= 10)) || (defined(WIN32) && defined(_MSC_VER))
277 #define CPL_FRMT_GB_WITHOUT_PREFIX "I64"
280 #define CPL_FRMT_GB_WITHOUT_PREFIX "ll"
284 #define CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"
286 #define CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"
289 #ifdef COMPAT_WITH_ICC_CONVERSION_CHECK
290 #define CPL_INT64_FITS_ON_INT32(x) ((x) >= INT_MIN && (x) <= INT_MAX)
292 #define CPL_INT64_FITS_ON_INT32(x) (CPL_STATIC_CAST(GIntBig, CPL_STATIC_CAST(int, x)) == (x))
301 # define CPL_C_START extern "C" {
310 #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
311 # ifdef GDAL_COMPILATION
312 # define CPL_DLL __declspec(dllexport)
316 # define CPL_INTERNAL
318 # if defined(USE_GCC_VISIBILITY_FLAG)
319 # define CPL_DLL __attribute__ ((visibility("default")))
320 # if !defined(__MINGW32__)
321 # define CPL_INTERNAL __attribute__((visibility("hidden")))
323 # define CPL_INTERNAL
327 # define CPL_INTERNAL
332 #define CPL_UNSTABLE_API CPL_DLL
338 #ifdef CPL_OPTIONAL_APIS
339 # define CPL_ODLL CPL_DLL
346 #if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL)
347 # define CPL_STDCALL __stdcall
355 # define FORCE_CDECL __cdecl
363 #if (defined(__GNUC__) && !defined(__NO_INLINE__)) || defined(_MSC_VER)
364 #define HAS_CPL_INLINE 1
365 #define CPL_INLINE __inline
366 #elif defined(__SUNPRO_CC)
367 #define HAS_CPL_INLINE 1
368 #define CPL_INLINE inline
376 # define MIN(a,b) (((a)<(b)) ? (a) : (b))
378 # define MAX(a,b) (((a)>(b)) ? (a) : (b))
383 # define ABS(x) (((x)<0) ? (-1*(x)) : (x))
388 # define M_PI 3.14159265358979323846
399 # define CPLIsEqual(x,y) (fabs((x) - (y)) < 0.0000000000001)
408 #if defined(AFL_FRIENDLY) && defined(__GNUC__)
410 static inline int CPL_afl_friendly_memcmp(
const void* ptr1,
const void* ptr2,
size_t len)
411 __attribute__((always_inline));
413 static inline int CPL_afl_friendly_memcmp(
const void* ptr1,
const void* ptr2,
size_t len)
415 const unsigned char* bptr1 = (
const unsigned char*)ptr1;
416 const unsigned char* bptr2 = (
const unsigned char*)ptr2;
419 unsigned char b1 = *(bptr1++);
420 unsigned char b2 = *(bptr2++);
421 if( b1 != b2 )
return b1 - b2;
426 static inline int CPL_afl_friendly_strcmp(
const char* ptr1,
const char* ptr2)
427 __attribute__((always_inline));
429 static inline int CPL_afl_friendly_strcmp(
const char* ptr1,
const char* ptr2)
431 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
432 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
435 unsigned char ch1 = *(usptr1++);
436 unsigned char ch2 = *(usptr2++);
437 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
441 static inline int CPL_afl_friendly_strncmp(
const char* ptr1,
const char* ptr2,
size_t len)
442 __attribute__((always_inline));
444 static inline int CPL_afl_friendly_strncmp(
const char* ptr1,
const char* ptr2,
size_t len)
446 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
447 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
450 unsigned char ch1 = *(usptr1++);
451 unsigned char ch2 = *(usptr2++);
452 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
457 static inline int CPL_afl_friendly_strcasecmp(
const char* ptr1,
const char* ptr2)
458 __attribute__((always_inline));
460 static inline int CPL_afl_friendly_strcasecmp(
const char* ptr1,
const char* ptr2)
462 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
463 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
466 unsigned char ch1 = *(usptr1++);
467 unsigned char ch2 = *(usptr2++);
468 ch1 = (
unsigned char)toupper(ch1);
469 ch2 = (
unsigned char)toupper(ch2);
470 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
474 static inline int CPL_afl_friendly_strncasecmp(
const char* ptr1,
const char* ptr2,
size_t len)
475 __attribute__((always_inline));
477 static inline int CPL_afl_friendly_strncasecmp(
const char* ptr1,
const char* ptr2,
size_t len)
479 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
480 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
483 unsigned char ch1 = *(usptr1++);
484 unsigned char ch2 = *(usptr2++);
485 ch1 = (
unsigned char)toupper(ch1);
486 ch2 = (
unsigned char)toupper(ch2);
487 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
492 static inline char* CPL_afl_friendly_strstr(
const char* haystack,
const char* needle)
493 __attribute__((always_inline));
495 static inline char* CPL_afl_friendly_strstr(
const char* haystack,
const char* needle)
497 const char* ptr_haystack = haystack;
500 const char* ptr_haystack2 = ptr_haystack;
501 const char* ptr_needle = needle;
504 char ch1 = *(ptr_haystack2++);
505 char ch2 = *(ptr_needle++);
507 return (
char*)ptr_haystack;
511 if( *ptr_haystack == 0 )
519 #define memcmp CPL_afl_friendly_memcmp
520 #define strcmp CPL_afl_friendly_strcmp
521 #define strncmp CPL_afl_friendly_strncmp
522 #define strcasecmp CPL_afl_friendly_strcasecmp
523 #define strncasecmp CPL_afl_friendly_strncasecmp
524 #define strstr CPL_afl_friendly_strstr
529 # define STRCASECMP(a,b) (_stricmp(a,b))
530 # define STRNCASECMP(a,b,n) (_strnicmp(a,b,n))
533 # define STRCASECMP(a,b) (strcasecmp(a,b))
535 # define STRNCASECMP(a,b,n) (strncasecmp(a,b,n))
538 # define EQUALN(a,b,n) (STRNCASECMP(a,b,n)==0)
540 # define EQUAL(a,b) (STRCASECMP(a,b)==0)
547 #ifndef STARTS_WITH_CI
549 #define STARTS_WITH(a,b) (strncmp(a,b,strlen(b)) == 0)
551 #define STARTS_WITH_CI(a,b) EQUALN(a,b,strlen(b))
555 #ifndef CPL_THREADLOCAL
556 # define CPL_THREADLOCAL
571 # define CPLIsNan(x) _isnan(x)
572 # define CPLIsInf(x) (!_isnan(x) && !_finite(x))
573 # define CPLIsFinite(x) _finite(x)
574 #elif defined(__GNUC__) && ( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 4 ) )
577 # define CPLIsNan(x) __builtin_isnan(x)
578 # define CPLIsInf(x) __builtin_isinf(x)
579 # define CPLIsFinite(x) __builtin_isfinite(x)
580 #elif defined(__cplusplus) && defined(HAVE_STD_IS_NAN) && HAVE_STD_IS_NAN
585 static inline int CPLIsNan(
float f) {
return std::isnan(f); }
586 static inline int CPLIsNan(
double f) {
return std::isnan(f); }
587 static inline int CPLIsInf(
float f) {
return std::isinf(f); }
588 static inline int CPLIsInf(
double f) {
return std::isinf(f); }
589 static inline int CPLIsFinite(
float f) {
return std::isfinite(f); }
590 static inline int CPLIsFinite(
double f) {
return std::isfinite(f); }
594 #if defined(__cplusplus) && defined(__GNUC__) && defined(__linux) && !defined(__ANDROID__) && !defined(CPL_SUPRESS_CPLUSPLUS)
598 static inline int CPLIsNan(
float f) {
return __isnanf(f); }
599 static inline int CPLIsNan(
double f) {
return __isnan(f); }
600 static inline int CPLIsInf(
float f) {
return __isinff(f); }
601 static inline int CPLIsInf(
double f) {
return __isinf(f); }
602 static inline int CPLIsFinite(
float f) {
return !__isnanf(f) && !__isinff(f); }
603 static inline int CPLIsFinite(
double f) {
return !__isnan(f) && !__isinf(f); }
606 # define CPLIsNan(x) isnan(x)
607 # if defined(isinf) || defined(__FreeBSD__)
609 # define CPLIsInf(x) isinf(x)
611 # define CPLIsFinite(x) (!isnan(x) && !isinf(x))
612 # elif defined(__sun__)
614 # define CPLIsInf(x) (!finite(x) && !isnan(x))
615 # define CPLIsFinite(x) finite(x)
617 # define CPLIsInf(x) (0)
618 # define CPLIsFinite(x) (!isnan(x))
631 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
635 #if ! ( defined(CPL_LSB) || defined(CPL_MSB) )
640 # define CPL_IS_LSB 1
642 # define CPL_IS_LSB 0
646 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
651 template <
bool b>
struct CPLStaticAssert {};
652 template<>
struct CPLStaticAssert<true>
654 static void my_function() {}
659 #define CPL_STATIC_ASSERT(x) CPLStaticAssert<x>::my_function()
660 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x) CPL_STATIC_ASSERT(x)
664 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x)
674 #define CPL_SWAP16(x) CPL_STATIC_CAST(GUInt16, (CPL_STATIC_CAST(GUInt16, x) << 8) | (CPL_STATIC_CAST(GUInt16, x) >> 8) )
676 #if defined(HAVE_GCC_BSWAP)
678 #define CPL_SWAP32(x) CPL_STATIC_CAST(GUInt32, __builtin_bswap32(CPL_STATIC_CAST(GUInt32, x)))
680 #define CPL_SWAP64(x) CPL_STATIC_CAST(GUInt64, __builtin_bswap64(CPL_STATIC_CAST(GUInt64, x)))
681 #elif defined(_MSC_VER)
682 #define CPL_SWAP32(x) CPL_STATIC_CAST(GUInt32, _byteswap_ulong(CPL_STATIC_CAST(GUInt32, x)))
683 #define CPL_SWAP64(x) CPL_STATIC_CAST(GUInt64, _byteswap_uint64(CPL_STATIC_CAST(GUInt64, x)))
686 #define CPL_SWAP32(x) \
687 CPL_STATIC_CAST(GUInt32, \
688 ((CPL_STATIC_CAST(GUInt32, x) & 0x000000ffU) << 24) | \
689 ((CPL_STATIC_CAST(GUInt32, x) & 0x0000ff00U) << 8) | \
690 ((CPL_STATIC_CAST(GUInt32, x) & 0x00ff0000U) >> 8) | \
691 ((CPL_STATIC_CAST(GUInt32, x) & 0xff000000U) >> 24) )
694 #define CPL_SWAP64(x) \
695 ((CPL_STATIC_CAST(GUInt64, CPL_SWAP32(CPL_STATIC_CAST(GUInt32, x))) << 32) | \
696 (CPL_STATIC_CAST(GUInt64, CPL_SWAP32(CPL_STATIC_CAST(GUInt32, CPL_STATIC_CAST(GUInt64, x) >> 32)))))
701 #define CPL_SWAP16PTR(x) \
705 memcpy(&_n16, _lx, 2); \
706 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2); \
707 _n16 = CPL_SWAP16(_n16); \
708 memcpy(_lx, &_n16, 2); \
712 #define CPL_SWAP32PTR(x) \
716 memcpy(&_n32, _lx, 4); \
717 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4); \
718 _n32 = CPL_SWAP32(_n32); \
719 memcpy(_lx, &_n32, 4); \
723 #define CPL_SWAP64PTR(x) \
727 memcpy(&_n64, _lx, 8); \
728 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8); \
729 _n64 = CPL_SWAP64(_n64); \
730 memcpy(_lx, &_n64, 8); \
734 #define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
737 # define CPL_MSBWORD16(x) (x)
738 # define CPL_LSBWORD16(x) CPL_SWAP16(x)
739 # define CPL_MSBWORD32(x) (x)
740 # define CPL_LSBWORD32(x) CPL_SWAP32(x)
741 # define CPL_MSBPTR16(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
742 # define CPL_LSBPTR16(x) CPL_SWAP16PTR(x)
743 # define CPL_MSBPTR32(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
744 # define CPL_LSBPTR32(x) CPL_SWAP32PTR(x)
745 # define CPL_MSBPTR64(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
746 # define CPL_LSBPTR64(x) CPL_SWAP64PTR(x)
749 # define CPL_LSBWORD16(x) (x)
751 # define CPL_MSBWORD16(x) CPL_SWAP16(x)
753 # define CPL_LSBWORD32(x) (x)
755 # define CPL_MSBWORD32(x) CPL_SWAP32(x)
757 # define CPL_LSBPTR16(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
759 # define CPL_MSBPTR16(x) CPL_SWAP16PTR(x)
761 # define CPL_LSBPTR32(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
763 # define CPL_MSBPTR32(x) CPL_SWAP32PTR(x)
765 # define CPL_LSBPTR64(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
767 # define CPL_MSBPTR64(x) CPL_SWAP64PTR(x)
773 #define CPL_LSBINT16PTR(x) ((*CPL_REINTERPRET_CAST(const GByte*, x)) | (*((CPL_REINTERPRET_CAST(const GByte*, x))+1) << 8))
778 #define CPL_LSBINT32PTR(x) ((*CPL_REINTERPRET_CAST(const GByte*, x)) | (*((CPL_REINTERPRET_CAST(const GByte*, x))+1) << 8) | \
779 (*((CPL_REINTERPRET_CAST(const GByte*, x))+2) << 16) | (*((CPL_REINTERPRET_CAST(const GByte*, x))+3) << 24))
782 #define CPL_LSBSINT16PTR(x) CPL_STATIC_CAST(GInt16,CPL_LSBINT16PTR(x))
785 #define CPL_LSBUINT16PTR(x) CPL_STATIC_CAST(GUInt16, CPL_LSBINT16PTR(x))
788 #define CPL_LSBSINT32PTR(x) CPL_STATIC_CAST(GInt32, CPL_LSBINT32PTR(x))
791 #define CPL_LSBUINT32PTR(x) CPL_STATIC_CAST(GUInt32, CPL_LSBINT32PTR(x))
795 #ifndef UNREFERENCED_PARAM
796 # ifdef UNREFERENCED_PARAMETER
797 # define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param)
799 # define UNREFERENCED_PARAM(param) ((void)param)
813 #ifndef DISABLE_CVSID
814 #if defined(__GNUC__) && __GNUC__ >= 4
815 # define CPL_CVSID(string) static const char cpl_cvsid[] __attribute__((used)) = string;
817 # define CPL_CVSID(string) static const char cpl_cvsid[] = string; \
818 static const char *cvsid_aw() { return( cvsid_aw() ? NULL : cpl_cvsid ); }
821 # define CPL_CVSID(string)
826 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) && !(defined(__MINGW64__) && __GNUC__ == 4 && __GNUC_MINOR__ == 6)
828 # define CPL_NULL_TERMINATED __attribute__((__sentinel__))
831 # define CPL_NULL_TERMINATED
834 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
836 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx)))
838 #define CPL_SCAN_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
841 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx )
843 #define CPL_SCAN_FUNC_FORMAT( format_idx, arg_idx )
846 #if defined(_MSC_VER) && (defined(GDAL_COMPILATION) || defined(CPL_ENABLE_MSVC_ANNOTATIONS))
850 # define CPL_FORMAT_STRING(arg) _Printf_format_string_ arg
853 # define CPL_SCANF_FORMAT_STRING(arg) _Scanf_format_string_ arg
856 # define CPL_FORMAT_STRING(arg) arg
858 # define CPL_SCANF_FORMAT_STRING(arg) arg
861 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
863 #define CPL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
866 #define CPL_WARN_UNUSED_RESULT
869 #if defined(__GNUC__) && __GNUC__ >= 4
871 # define CPL_UNUSED __attribute((__unused__))
878 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
880 #define CPL_NO_RETURN __attribute__((noreturn))
883 #define CPL_NO_RETURN
888 #ifndef __has_attribute
889 #define __has_attribute(x) 0
894 #if ((defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))) || __has_attribute(returns_nonnull)) && !defined(DOXYGEN_SKIP) && !defined(__INTEL_COMPILER)
896 # define CPL_RETURNS_NONNULL __attribute__((returns_nonnull))
899 # define CPL_RETURNS_NONNULL
902 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
904 #define CPL_RESTRICT __restrict__
910 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
914 # define CPL_OVERRIDE override
917 # define CPL_FINAL final
920 # define CPL_NON_FINAL
927 # define CPL_DISALLOW_COPY_ASSIGN(ClassName) \
928 ClassName( const ClassName & ) = delete; \
929 ClassName &operator=( const ClassName & ) = delete;
933 #if !defined(DOXYGEN_SKIP) && !defined(CPL_WARN_DEPRECATED)
934 #if defined(__has_extension)
935 #if __has_extension(attribute_deprecated_with_message)
937 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated(x)))
939 #define CPL_WARN_DEPRECATED(x)
941 #elif defined(__GNUC__)
942 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated))
944 #define CPL_WARN_DEPRECATED(x)
948 #if !defined(_MSC_VER) && !defined(__APPLE__) && !defined(_FORTIFY_SOURCE)
950 # if defined(GDAL_COMPILATION) && defined(WARN_STANDARD_PRINTF)
951 int vsnprintf(
char *str,
size_t size,
const char* fmt, va_list args)
952 CPL_WARN_DEPRECATED(
"Use CPLvsnprintf() instead");
953 int snprintf(
char *str,
size_t size,
const char* fmt, ...)
956 int sprintf(
char *str, const
char* fmt, ...)
959 # elif defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
960 int sprintf(
char *str,
const char* fmt, ...)
962 CPL_WARN_DEPRECATED("Use snprintf() or
CPLsnprintf() instead");
967 #if defined(MAKE_SANITIZE_HAPPY) || !(defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64))
969 #define CPL_CPU_REQUIRES_ALIGNED_ACCESS
973 #if defined(__cplusplus)
976 #define CPL_ARRAYSIZE(array) \
977 ((sizeof(array) / sizeof(*(array))) / \
978 static_cast<size_t>(!(sizeof(array) % sizeof(*(array)))))
981 #define CPL_ARRAYSIZE(array) (sizeof(array) / sizeof(array[0]))
985 template<
class T>
static void CPL_IGNORE_RET_VAL(
const T&) {}
986 inline static bool CPL_TO_BOOL(
int x) {
return x != 0; }
991 #if (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || (defined(__clang__) && __clang_major__ >= 3)) && !defined(_MSC_VER))
992 #define HAVE_GCC_DIAGNOSTIC_PUSH
995 #if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) && !defined(_MSC_VER))
996 #define HAVE_GCC_SYSTEM_HEADER
999 #if ((defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))) || __GNUC__ >= 7)
1001 # define CPL_FALLTHROUGH [[clang::fallthrough]];
1004 # define CPL_FALLTHROUGH
1017 #if __clang_major__ >= 4 || (__clang_major__ == 3 && __clang_minor__ >= 8)
1018 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW __attribute__((no_sanitize("unsigned-integer-overflow")))
1020 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
1023 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && defined(GDAL_COMPILATION)
1025 template<
class C,
class A,
class B>
1026 CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
1027 inline C CPLUnsanitizedAdd(A a, B b)
1034 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
1035 #define CPL_NULLPTR nullptr
1037 #define CPL_NULLPTR NULL
1046 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && !defined(DOXYGEN_SKIP)
int GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition: cpl_port.h:266
#define CPLIsInf(x)
Return whether a floating-pointer number is +/- infinity.
Definition: cpl_port.h:609
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:233
short GInt16
Int16 type.
Definition: cpl_port.h:199
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:303
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:301
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:249
int GBool
Type for boolean values (alias to int)
Definition: cpl_port.h:211
unsigned int GUInt32
Unsigned int32 type.
Definition: cpl_port.h:195
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:841
#define CPLIsNan(x)
Return whether a floating-pointer number is NaN.
Definition: cpl_port.h:606
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1053
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition: cpl_port.h:251
unsigned short GUInt16
Unsigned int16 type.
Definition: cpl_port.h:201
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:203
int GInt32
Int32 type.
Definition: cpl_port.h:193
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:230
#define CPLIsFinite(x)
Return whether a floating-pointer number is finite.
Definition: cpl_port.h:611
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
snprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1349