Go to the documentation of this file.
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)
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
264 #elif SIZEOF_VOIDP == 8
272 #ifdef GDAL_COMPILATION
274 typedef uintptr_t GUIntptr_t;
275 #define CPL_IS_ALIGNED(ptr, quant) ((CPL_REINTERPRET_CAST(GUIntptr_t, CPL_STATIC_CAST(const void*, ptr)) % (quant)) == 0)
279 #if (defined(__MSVCRT__) && !(defined(__MINGW64__) && __GNUC__ >= 10)) || (defined(WIN32) && defined(_MSC_VER))
280 #define CPL_FRMT_GB_WITHOUT_PREFIX "I64"
283 #define CPL_FRMT_GB_WITHOUT_PREFIX "ll"
287 #define CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"
289 #define CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"
292 #ifdef COMPAT_WITH_ICC_CONVERSION_CHECK
293 #define CPL_INT64_FITS_ON_INT32(x) ((x) >= INT_MIN && (x) <= INT_MAX)
295 #define CPL_INT64_FITS_ON_INT32(x) (CPL_STATIC_CAST(GIntBig, CPL_STATIC_CAST(int, x)) == (x))
304 # define CPL_C_START extern "C" {
313 #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
314 # ifdef GDAL_COMPILATION
315 # define CPL_DLL __declspec(dllexport)
319 # define CPL_INTERNAL
321 # if defined(USE_GCC_VISIBILITY_FLAG)
322 # define CPL_DLL __attribute__ ((visibility("default")))
323 # if !defined(__MINGW32__)
324 # define CPL_INTERNAL __attribute__((visibility("hidden")))
326 # define CPL_INTERNAL
330 # define CPL_INTERNAL
335 #define CPL_UNSTABLE_API CPL_DLL
341 #ifdef CPL_OPTIONAL_APIS
342 # define CPL_ODLL CPL_DLL
349 #if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL)
350 # define CPL_STDCALL __stdcall
358 # define FORCE_CDECL __cdecl
366 #if (defined(__GNUC__) && !defined(__NO_INLINE__)) || defined(_MSC_VER)
367 #define HAS_CPL_INLINE 1
368 #define CPL_INLINE __inline
369 #elif defined(__SUNPRO_CC)
370 #define HAS_CPL_INLINE 1
371 #define CPL_INLINE inline
379 # define MIN(a,b) (((a)<(b)) ? (a) : (b))
381 # define MAX(a,b) (((a)>(b)) ? (a) : (b))
386 # define ABS(x) (((x)<0) ? (-1*(x)) : (x))
391 # define M_PI 3.14159265358979323846
402 # define CPLIsEqual(x,y) (fabs((x) - (y)) < 0.0000000000001)
411 #if defined(AFL_FRIENDLY) && defined(__GNUC__)
413 static inline int CPL_afl_friendly_memcmp(
const void* ptr1,
const void* ptr2,
size_t len)
414 __attribute__((always_inline));
416 static inline int CPL_afl_friendly_memcmp(
const void* ptr1,
const void* ptr2,
size_t len)
418 const unsigned char* bptr1 = (
const unsigned char*)ptr1;
419 const unsigned char* bptr2 = (
const unsigned char*)ptr2;
422 unsigned char b1 = *(bptr1++);
423 unsigned char b2 = *(bptr2++);
424 if( b1 != b2 )
return b1 - b2;
429 static inline int CPL_afl_friendly_strcmp(
const char* ptr1,
const char* ptr2)
430 __attribute__((always_inline));
432 static inline int CPL_afl_friendly_strcmp(
const char* ptr1,
const char* ptr2)
434 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
435 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
438 unsigned char ch1 = *(usptr1++);
439 unsigned char ch2 = *(usptr2++);
440 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
444 static inline int CPL_afl_friendly_strncmp(
const char* ptr1,
const char* ptr2,
size_t len)
445 __attribute__((always_inline));
447 static inline int CPL_afl_friendly_strncmp(
const char* ptr1,
const char* ptr2,
size_t len)
449 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
450 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
453 unsigned char ch1 = *(usptr1++);
454 unsigned char ch2 = *(usptr2++);
455 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
460 static inline int CPL_afl_friendly_strcasecmp(
const char* ptr1,
const char* ptr2)
461 __attribute__((always_inline));
463 static inline int CPL_afl_friendly_strcasecmp(
const char* ptr1,
const char* ptr2)
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 ch1 = (
unsigned char)toupper(ch1);
472 ch2 = (
unsigned char)toupper(ch2);
473 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
477 static inline int CPL_afl_friendly_strncasecmp(
const char* ptr1,
const char* ptr2,
size_t len)
478 __attribute__((always_inline));
480 static inline int CPL_afl_friendly_strncasecmp(
const char* ptr1,
const char* ptr2,
size_t len)
482 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
483 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
486 unsigned char ch1 = *(usptr1++);
487 unsigned char ch2 = *(usptr2++);
488 ch1 = (
unsigned char)toupper(ch1);
489 ch2 = (
unsigned char)toupper(ch2);
490 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
495 static inline char* CPL_afl_friendly_strstr(
const char* haystack,
const char* needle)
496 __attribute__((always_inline));
498 static inline char* CPL_afl_friendly_strstr(
const char* haystack,
const char* needle)
500 const char* ptr_haystack = haystack;
503 const char* ptr_haystack2 = ptr_haystack;
504 const char* ptr_needle = needle;
507 char ch1 = *(ptr_haystack2++);
508 char ch2 = *(ptr_needle++);
510 return (
char*)ptr_haystack;
514 if( *ptr_haystack == 0 )
522 #define memcmp CPL_afl_friendly_memcmp
523 #define strcmp CPL_afl_friendly_strcmp
524 #define strncmp CPL_afl_friendly_strncmp
525 #define strcasecmp CPL_afl_friendly_strcasecmp
526 #define strncasecmp CPL_afl_friendly_strncasecmp
527 #define strstr CPL_afl_friendly_strstr
532 # define STRCASECMP(a,b) (_stricmp(a,b))
533 # define STRNCASECMP(a,b,n) (_strnicmp(a,b,n))
536 # define STRCASECMP(a,b) (strcasecmp(a,b))
538 # define STRNCASECMP(a,b,n) (strncasecmp(a,b,n))
541 # define EQUALN(a,b,n) (STRNCASECMP(a,b,n)==0)
543 # define EQUAL(a,b) (STRCASECMP(a,b)==0)
550 #ifndef STARTS_WITH_CI
552 #define STARTS_WITH(a,b) (strncmp(a,b,strlen(b)) == 0)
554 #define STARTS_WITH_CI(a,b) EQUALN(a,b,strlen(b))
558 #ifndef CPL_THREADLOCAL
559 # define CPL_THREADLOCAL
574 # define CPLIsNan(x) _isnan(x)
575 # define CPLIsInf(x) (!_isnan(x) && !_finite(x))
576 # define CPLIsFinite(x) _finite(x)
577 #elif defined(__GNUC__) && ( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 4 ) )
580 # define CPLIsNan(x) __builtin_isnan(x)
581 # define CPLIsInf(x) __builtin_isinf(x)
582 # define CPLIsFinite(x) __builtin_isfinite(x)
583 #elif defined(__cplusplus) && defined(HAVE_STD_IS_NAN) && HAVE_STD_IS_NAN
588 static inline int CPLIsNan(
float f) {
return std::isnan(f); }
589 static inline int CPLIsNan(
double f) {
return std::isnan(f); }
590 static inline int CPLIsInf(
float f) {
return std::isinf(f); }
591 static inline int CPLIsInf(
double f) {
return std::isinf(f); }
592 static inline int CPLIsFinite(
float f) {
return std::isfinite(f); }
593 static inline int CPLIsFinite(
double f) {
return std::isfinite(f); }
597 #if defined(__cplusplus) && defined(__GNUC__) && defined(__linux) && !defined(__ANDROID__) && !defined(CPL_SUPRESS_CPLUSPLUS)
601 static inline int CPLIsNan(
float f) {
return __isnanf(f); }
602 static inline int CPLIsNan(
double f) {
return __isnan(f); }
603 static inline int CPLIsInf(
float f) {
return __isinff(f); }
604 static inline int CPLIsInf(
double f) {
return __isinf(f); }
605 static inline int CPLIsFinite(
float f) {
return !__isnanf(f) && !__isinff(f); }
606 static inline int CPLIsFinite(
double f) {
return !__isnan(f) && !__isinf(f); }
609 # define CPLIsNan(x) isnan(x)
610 # if defined(isinf) || defined(__FreeBSD__)
612 # define CPLIsInf(x) isinf(x)
614 # define CPLIsFinite(x) (!isnan(x) && !isinf(x))
615 # elif defined(__sun__)
617 # define CPLIsInf(x) (!finite(x) && !isnan(x))
618 # define CPLIsFinite(x) finite(x)
620 # define CPLIsInf(x) (0)
621 # define CPLIsFinite(x) (!isnan(x))
634 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
638 #if ! ( defined(CPL_LSB) || defined(CPL_MSB) )
643 # define CPL_IS_LSB 1
645 # define CPL_IS_LSB 0
649 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
654 template <
bool b>
struct CPLStaticAssert {};
655 template<>
struct CPLStaticAssert<true>
657 static void my_function() {}
662 #define CPL_STATIC_ASSERT(x) CPLStaticAssert<x>::my_function()
663 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x) CPL_STATIC_ASSERT(x)
667 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x)
677 #define CPL_SWAP16(x) CPL_STATIC_CAST(GUInt16, (CPL_STATIC_CAST(GUInt16, x) << 8) | (CPL_STATIC_CAST(GUInt16, x) >> 8) )
679 #if defined(HAVE_GCC_BSWAP)
681 #define CPL_SWAP32(x) CPL_STATIC_CAST(GUInt32, __builtin_bswap32(CPL_STATIC_CAST(GUInt32, x)))
683 #define CPL_SWAP64(x) CPL_STATIC_CAST(GUInt64, __builtin_bswap64(CPL_STATIC_CAST(GUInt64, x)))
684 #elif defined(_MSC_VER)
685 #define CPL_SWAP32(x) CPL_STATIC_CAST(GUInt32, _byteswap_ulong(CPL_STATIC_CAST(GUInt32, x)))
686 #define CPL_SWAP64(x) CPL_STATIC_CAST(GUInt64, _byteswap_uint64(CPL_STATIC_CAST(GUInt64, x)))
689 #define CPL_SWAP32(x) \
690 CPL_STATIC_CAST(GUInt32, \
691 ((CPL_STATIC_CAST(GUInt32, x) & 0x000000ffU) << 24) | \
692 ((CPL_STATIC_CAST(GUInt32, x) & 0x0000ff00U) << 8) | \
693 ((CPL_STATIC_CAST(GUInt32, x) & 0x00ff0000U) >> 8) | \
694 ((CPL_STATIC_CAST(GUInt32, x) & 0xff000000U) >> 24) )
697 #define CPL_SWAP64(x) \
698 ((CPL_STATIC_CAST(GUInt64, CPL_SWAP32(CPL_STATIC_CAST(GUInt32, x))) << 32) | \
699 (CPL_STATIC_CAST(GUInt64, CPL_SWAP32(CPL_STATIC_CAST(GUInt32, CPL_STATIC_CAST(GUInt64, x) >> 32)))))
704 #define CPL_SWAP16PTR(x) \
708 memcpy(&_n16, _lx, 2); \
709 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2); \
710 _n16 = CPL_SWAP16(_n16); \
711 memcpy(_lx, &_n16, 2); \
715 #define CPL_SWAP32PTR(x) \
719 memcpy(&_n32, _lx, 4); \
720 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4); \
721 _n32 = CPL_SWAP32(_n32); \
722 memcpy(_lx, &_n32, 4); \
726 #define CPL_SWAP64PTR(x) \
730 memcpy(&_n64, _lx, 8); \
731 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8); \
732 _n64 = CPL_SWAP64(_n64); \
733 memcpy(_lx, &_n64, 8); \
737 #define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
740 # define CPL_MSBWORD16(x) (x)
741 # define CPL_LSBWORD16(x) CPL_SWAP16(x)
742 # define CPL_MSBWORD32(x) (x)
743 # define CPL_LSBWORD32(x) CPL_SWAP32(x)
744 # define CPL_MSBPTR16(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
745 # define CPL_LSBPTR16(x) CPL_SWAP16PTR(x)
746 # define CPL_MSBPTR32(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
747 # define CPL_LSBPTR32(x) CPL_SWAP32PTR(x)
748 # define CPL_MSBPTR64(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
749 # define CPL_LSBPTR64(x) CPL_SWAP64PTR(x)
752 # define CPL_LSBWORD16(x) (x)
754 # define CPL_MSBWORD16(x) CPL_SWAP16(x)
756 # define CPL_LSBWORD32(x) (x)
758 # define CPL_MSBWORD32(x) CPL_SWAP32(x)
760 # define CPL_LSBPTR16(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
762 # define CPL_MSBPTR16(x) CPL_SWAP16PTR(x)
764 # define CPL_LSBPTR32(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
766 # define CPL_MSBPTR32(x) CPL_SWAP32PTR(x)
768 # define CPL_LSBPTR64(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
770 # define CPL_MSBPTR64(x) CPL_SWAP64PTR(x)
776 #define CPL_LSBINT16PTR(x) ((*CPL_REINTERPRET_CAST(const GByte*, x)) | (*((CPL_REINTERPRET_CAST(const GByte*, x))+1) << 8))
781 #define CPL_LSBINT32PTR(x) ((*CPL_REINTERPRET_CAST(const GByte*, x)) | (*((CPL_REINTERPRET_CAST(const GByte*, x))+1) << 8) | \
782 (*((CPL_REINTERPRET_CAST(const GByte*, x))+2) << 16) | (*((CPL_REINTERPRET_CAST(const GByte*, x))+3) << 24))
785 #define CPL_LSBSINT16PTR(x) CPL_STATIC_CAST(GInt16,CPL_LSBINT16PTR(x))
788 #define CPL_LSBUINT16PTR(x) CPL_STATIC_CAST(GUInt16, CPL_LSBINT16PTR(x))
791 #define CPL_LSBSINT32PTR(x) CPL_STATIC_CAST(GInt32, CPL_LSBINT32PTR(x))
794 #define CPL_LSBUINT32PTR(x) CPL_STATIC_CAST(GUInt32, CPL_LSBINT32PTR(x))
798 #ifndef UNREFERENCED_PARAM
799 # ifdef UNREFERENCED_PARAMETER
800 # define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param)
802 # define UNREFERENCED_PARAM(param) ((void)param)
816 #ifndef DISABLE_CVSID
817 #if defined(__GNUC__) && __GNUC__ >= 4
818 # define CPL_CVSID(string) static const char cpl_cvsid[] __attribute__((used)) = string;
820 # define CPL_CVSID(string) static const char cpl_cvsid[] = string; \
821 static const char *cvsid_aw() { return( cvsid_aw() ? NULL : cpl_cvsid ); }
824 # define CPL_CVSID(string)
829 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) && !(defined(__MINGW64__) && __GNUC__ == 4 && __GNUC_MINOR__ == 6)
831 # define CPL_NULL_TERMINATED __attribute__((__sentinel__))
834 # define CPL_NULL_TERMINATED
837 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
839 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx)))
841 #define CPL_SCAN_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
844 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx )
846 #define CPL_SCAN_FUNC_FORMAT( format_idx, arg_idx )
849 #if defined(_MSC_VER) && (defined(GDAL_COMPILATION) || defined(CPL_ENABLE_MSVC_ANNOTATIONS))
853 # define CPL_FORMAT_STRING(arg) _Printf_format_string_ arg
856 # define CPL_SCANF_FORMAT_STRING(arg) _Scanf_format_string_ arg
859 # define CPL_FORMAT_STRING(arg) arg
861 # define CPL_SCANF_FORMAT_STRING(arg) arg
864 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
866 #define CPL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
869 #define CPL_WARN_UNUSED_RESULT
872 #if defined(__GNUC__) && __GNUC__ >= 4
874 # define CPL_UNUSED __attribute((__unused__))
881 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
883 #define CPL_NO_RETURN __attribute__((noreturn))
886 #define CPL_NO_RETURN
891 #ifndef __has_attribute
892 #define __has_attribute(x) 0 // Compatibility with non-clang compilers.
897 #if ((defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))) || __has_attribute(returns_nonnull)) && !defined(DOXYGEN_SKIP) && !defined(__INTEL_COMPILER)
899 # define CPL_RETURNS_NONNULL __attribute__((returns_nonnull))
902 # define CPL_RETURNS_NONNULL
905 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
907 #define CPL_RESTRICT __restrict__
913 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
917 # define CPL_OVERRIDE override
920 # define CPL_FINAL final
923 # define CPL_NON_FINAL
930 # define CPL_DISALLOW_COPY_ASSIGN(ClassName) \
931 ClassName( const ClassName & ) = delete; \
932 ClassName &operator=( const ClassName & ) = delete;
936 #if !defined(DOXYGEN_SKIP) && !defined(CPL_WARN_DEPRECATED)
937 #if defined(__has_extension)
938 #if __has_extension(attribute_deprecated_with_message)
940 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated(x)))
942 #define CPL_WARN_DEPRECATED(x)
944 #elif defined(__GNUC__)
945 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated))
947 #define CPL_WARN_DEPRECATED(x)
951 #if !defined(_MSC_VER) && !defined(__APPLE__) && !defined(_FORTIFY_SOURCE)
953 # if defined(GDAL_COMPILATION) && defined(WARN_STANDARD_PRINTF)
954 int vsnprintf(
char *str,
size_t size,
const char* fmt, va_list args)
955 CPL_WARN_DEPRECATED(
"Use CPLvsnprintf() instead");
956 int snprintf(
char *str,
size_t size,
const char* fmt, ...)
959 int sprintf(
char *str, const
char* fmt, ...)
962 # elif defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
963 int sprintf(
char *str,
const char* fmt, ...)
965 CPL_WARN_DEPRECATED("Use snprintf() or
CPLsnprintf() instead");
970 #if defined(MAKE_SANITIZE_HAPPY) || !(defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64))
972 #define CPL_CPU_REQUIRES_ALIGNED_ACCESS
976 #if defined(__cplusplus)
979 #define CPL_ARRAYSIZE(array) \
980 ((sizeof(array) / sizeof(*(array))) / \
981 static_cast<size_t>(!(sizeof(array) % sizeof(*(array)))))
984 #define CPL_ARRAYSIZE(array) (sizeof(array) / sizeof(array[0]))
988 template<
class T>
static void CPL_IGNORE_RET_VAL(
const T&) {}
989 inline static bool CPL_TO_BOOL(
int x) {
return x != 0; }
994 #if (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || (defined(__clang__) && __clang_major__ >= 3)) && !defined(_MSC_VER))
995 #define HAVE_GCC_DIAGNOSTIC_PUSH
998 #if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) && !defined(_MSC_VER))
999 #define HAVE_GCC_SYSTEM_HEADER
1002 #if ((defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))) || __GNUC__ >= 7)
1004 # define CPL_FALLTHROUGH [[clang::fallthrough]];
1007 # define CPL_FALLTHROUGH
1020 #if __clang_major__ >= 4 || (__clang_major__ == 3 && __clang_minor__ >= 8)
1021 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW __attribute__((no_sanitize("unsigned-integer-overflow")))
1023 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
1026 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && defined(GDAL_COMPILATION)
1028 template<
class C,
class A,
class B>
1029 CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
1030 inline C CPLUnsanitizedAdd(A a, B b)
1037 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
1038 #define CPL_NULLPTR nullptr
1040 #define CPL_NULLPTR NULL
1049 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && !defined(DOXYGEN_SKIP)
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:844
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:203
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition: cpl_port.h:251
short GInt16
Int16 type.
Definition: cpl_port.h:199
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
snprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1353
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:249
int GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition: cpl_port.h:269
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:304
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1056
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:233
#define CPLIsNan(x)
Return whether a floating-pointer number is NaN.
Definition: cpl_port.h:609
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:306
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:230
int GBool
Type for boolean values (alias to int)
Definition: cpl_port.h:211
#define CPLIsInf(x)
Return whether a floating-pointer number is +/- infinity.
Definition: cpl_port.h:612
unsigned short GUInt16
Unsigned int16 type.
Definition: cpl_port.h:201
int GInt32
Int32 type.
Definition: cpl_port.h:193
#define CPLIsFinite(x)
Return whether a floating-pointer number is finite.
Definition: cpl_port.h:614
unsigned int GUInt32
Unsigned int32 type.
Definition: cpl_port.h:195