15#ifndef CPL_BASE_H_INCLUDED
16#define CPL_BASE_H_INCLUDED
30#ifndef _CRT_SECURE_NO_DEPRECATE
31#define _CRT_SECURE_NO_DEPRECATE
33#ifndef _CRT_NONSTDC_NO_DEPRECATE
34#define _CRT_NONSTDC_NO_DEPRECATE
38#include "cpl_config.h"
45#if !defined(SIZEOF_INT) || SIZEOF_INT != 4
46#error "Unexpected value for SIZEOF_INT"
49#if !defined(SIZEOF_UNSIGNED_LONG) || \
50 (SIZEOF_UNSIGNED_LONG != 4 && SIZEOF_UNSIGNED_LONG != 8)
51#error "Unexpected value for SIZEOF_UNSIGNED_LONG"
54#if !defined(SIZEOF_VOIDP)
55#error "Unexpected value for SIZEOF_VOIDP"
68#if defined(VSI_NEED_LARGEFILE64_SOURCE) && !defined(_LARGEFILE64_SOURCE)
69#define _LARGEFILE64_SOURCE 1
78#if defined(HAVE_ICONV)
79#define CPL_RECODE_ICONV
82#define CPL_RECODE_STUB
90#if defined(GDAL_COMPILATION) && defined(__sun__) && \
91 (__STDC_VERSION__ + 0) >= 201112L && (_XOPEN_SOURCE + 0) < 600
95#define _XOPEN_SOURCE 600
141#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
142#if !(__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900))
143#error Must have C++11 or newer.
171#ifndef CPL_GBOOL_DEFINED
173#define CPL_GBOOL_DEFINED
181#define CPL_STATIC_CAST(type, expr) static_cast<type>(expr)
182#define CPL_REINTERPRET_CAST(type, expr) reinterpret_cast<type>(expr)
184#define CPL_STATIC_CAST(type, expr) ((type)(expr))
185#define CPL_REINTERPRET_CAST(type, expr) ((type)(expr))
201#define GINTBIG_MIN (CPL_STATIC_CAST(GIntBig, 0x80000000) << 32)
203#define GINTBIG_MAX ((CPL_STATIC_CAST(GIntBig, 0x7FFFFFFF) << 32) | 0xFFFFFFFFU)
205#define GUINTBIG_MAX \
206 ((CPL_STATIC_CAST(GUIntBig, 0xFFFFFFFFU) << 32) | 0xFFFFFFFFU)
209#define CPL_HAS_GINT64 1
221#define GINT64_MIN GINTBIG_MIN
223#define GINT64_MAX GINTBIG_MAX
225#define GUINT64_MAX GUINTBIG_MAX
231#elif SIZEOF_VOIDP == 8
239#ifdef GDAL_COMPILATION
241typedef uintptr_t GUIntptr_t;
242#define CPL_IS_ALIGNED(ptr, quant) \
243 ((CPL_REINTERPRET_CAST(GUIntptr_t, CPL_STATIC_CAST(const void *, ptr)) % \
248#if (defined(__MSVCRT__) && !(defined(__MINGW64__) && __GNUC__ >= 10)) || \
249 (defined(_WIN32) && defined(_MSC_VER))
250#define CPL_FRMT_GB_WITHOUT_PREFIX "I64"
253#define CPL_FRMT_GB_WITHOUT_PREFIX "ll"
257#define CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"
259#define CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"
262#ifdef COMPAT_WITH_ICC_CONVERSION_CHECK
263#define CPL_INT64_FITS_ON_INT32(x) ((x) >= INT_MIN && (x) <= INT_MAX)
265#define CPL_INT64_FITS_ON_INT32(x) \
266 (CPL_STATIC_CAST(GIntBig, CPL_STATIC_CAST(int, x)) == (x))
286#if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
287#ifdef GDAL_COMPILATION
288#define CPL_DLL __declspec(dllexport)
294#if defined(USE_GCC_VISIBILITY_FLAG)
295#define CPL_DLL __attribute__((visibility("default")))
296#if !defined(__MINGW32__)
297#define CPL_INTERNAL __attribute__((visibility("hidden")))
308#define CPL_UNSTABLE_API CPL_DLL
314#ifdef CPL_OPTIONAL_APIS
315#define CPL_ODLL CPL_DLL
322#if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL)
323#define CPL_STDCALL __stdcall
331#define FORCE_CDECL __cdecl
339#if (defined(__GNUC__) && !defined(__NO_INLINE__)) || defined(_MSC_VER)
340#define HAS_CPL_INLINE 1
341#define CPL_INLINE __inline
342#elif defined(__SUNPRO_CC)
343#define HAS_CPL_INLINE 1
344#define CPL_INLINE inline
351#define CPL_MIN(a, b) (((a) < (b)) ? (a) : (b))
353#define CPL_MAX(a, b) (((a) > (b)) ? (a) : (b))
356#define CPL_ABS(x) (((x) < 0) ? (-1 * (x)) : (x))
360#if defined(GDAL_COMPILATION)
362#define M_PI 3.14159265358979323846
376#define CPLIsEqual(x, y) (fabs((x) - (y)) < 0.0000000000001)
385#if defined(AFL_FRIENDLY) && defined(__GNUC__)
387static inline int CPL_afl_friendly_memcmp(
const void *ptr1,
const void *ptr2,
389 __attribute__((always_inline));
391static inline int CPL_afl_friendly_memcmp(
const void *ptr1,
const void *ptr2,
394 const unsigned char *bptr1 = (
const unsigned char *)ptr1;
395 const unsigned char *bptr2 = (
const unsigned char *)ptr2;
398 unsigned char b1 = *(bptr1++);
399 unsigned char b2 = *(bptr2++);
406static inline int CPL_afl_friendly_strcmp(
const char *ptr1,
const char *ptr2)
407 __attribute__((always_inline));
409static inline int CPL_afl_friendly_strcmp(
const char *ptr1,
const char *ptr2)
411 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
412 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
415 unsigned char ch1 = *(usptr1++);
416 unsigned char ch2 = *(usptr2++);
417 if (ch1 == 0 || ch1 != ch2)
422static inline int CPL_afl_friendly_strncmp(
const char *ptr1,
const char *ptr2,
424 __attribute__((always_inline));
426static inline int CPL_afl_friendly_strncmp(
const char *ptr1,
const char *ptr2,
429 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
430 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
433 unsigned char ch1 = *(usptr1++);
434 unsigned char ch2 = *(usptr2++);
435 if (ch1 == 0 || ch1 != ch2)
441static inline int CPL_afl_friendly_strcasecmp(
const char *ptr1,
443 __attribute__((always_inline));
445static inline int CPL_afl_friendly_strcasecmp(
const char *ptr1,
448 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
449 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
452 unsigned char ch1 = *(usptr1++);
453 unsigned char ch2 = *(usptr2++);
454 ch1 = (
unsigned char)toupper(ch1);
455 ch2 = (
unsigned char)toupper(ch2);
456 if (ch1 == 0 || ch1 != ch2)
461static inline int CPL_afl_friendly_strncasecmp(
const char *ptr1,
462 const char *ptr2,
size_t len)
463 __attribute__((always_inline));
465static inline int CPL_afl_friendly_strncasecmp(
const char *ptr1,
466 const char *ptr2,
size_t len)
468 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
469 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
472 unsigned char ch1 = *(usptr1++);
473 unsigned char ch2 = *(usptr2++);
474 ch1 = (
unsigned char)toupper(ch1);
475 ch2 = (
unsigned char)toupper(ch2);
476 if (ch1 == 0 || ch1 != ch2)
482static inline char *CPL_afl_friendly_strstr(
const char *haystack,
484 __attribute__((always_inline));
486static inline char *CPL_afl_friendly_strstr(
const char *haystack,
489 const char *ptr_haystack = haystack;
492 const char *ptr_haystack2 = ptr_haystack;
493 const char *ptr_needle = needle;
496 char ch1 = *(ptr_haystack2++);
497 char ch2 = *(ptr_needle++);
499 return (
char *)ptr_haystack;
503 if (*ptr_haystack == 0)
511#define memcmp CPL_afl_friendly_memcmp
512#define strcmp CPL_afl_friendly_strcmp
513#define strncmp CPL_afl_friendly_strncmp
514#define strcasecmp CPL_afl_friendly_strcasecmp
515#define strncasecmp CPL_afl_friendly_strncasecmp
516#define strstr CPL_afl_friendly_strstr
521#define STRCASECMP(a, b) (_stricmp(a, b))
522#define STRNCASECMP(a, b, n) (_strnicmp(a, b, n))
525#define STRCASECMP(a, b) (strcasecmp(a, b))
527#define STRNCASECMP(a, b, n) (strncasecmp(a, b, n))
530#define EQUALN(a, b, n) (STRNCASECMP(a, b, n) == 0)
532#define EQUAL(a, b) (STRCASECMP(a, b) == 0)
539#ifndef STARTS_WITH_CI
541#define STARTS_WITH(a, b) (strncmp(a, b, strlen(b)) == 0)
543#define STARTS_WITH_CI(a, b) EQUALN(a, b, strlen(b))
547#ifndef CPL_THREADLOCAL
548#define CPL_THREADLOCAL
565#define CPLIsNan(x) _isnan(x)
566#define CPLIsInf(x) (!_isnan(x) && !_finite(x))
567#define CPLIsFinite(x) _finite(x)
568#elif defined(__GNUC__) && \
569 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
572#define CPLIsNan(x) __builtin_isnan(x)
573#define CPLIsInf(x) __builtin_isinf(x)
574#define CPLIsFinite(x) __builtin_isfinite(x)
575#elif defined(isinf) || defined(__FreeBSD__)
577#define CPLIsNan(x) isnan(x)
579#define CPLIsInf(x) isinf(x)
581#define CPLIsFinite(x) (!isnan(x) && !isinf(x))
582#elif defined(__sun__)
584#define CPLIsNan(x) isnan(x)
585#define CPLIsInf(x) (!finite(x) && !isnan(x))
586#define CPLIsFinite(x) finite(x)
588#define CPLIsNan(x) ((x) != (x))
589#define CPLIsInf(x) (0)
590#define CPLIsFinite(x) (!isnan(x))
603#if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
607#if !(defined(CPL_LSB) || defined(CPL_MSB))
618#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
624 template <
bool b>
struct CPLStaticAssert
628 template <>
struct CPLStaticAssert<true>
630 static void my_function()
637#define CPL_STATIC_ASSERT(x) CPLStaticAssert<x>::my_function()
638#define CPL_STATIC_ASSERT_IF_AVAILABLE(x) CPL_STATIC_ASSERT(x)
642#define CPL_STATIC_ASSERT_IF_AVAILABLE(x)
652#define CPL_SWAP16(x) \
653 CPL_STATIC_CAST(GUInt16, (CPL_STATIC_CAST(GUInt16, x) << 8) | \
654 (CPL_STATIC_CAST(GUInt16, x) >> 8))
658#define CPL_SWAP32(x) \
659 CPL_STATIC_CAST(GUInt32, __builtin_bswap32(CPL_STATIC_CAST(GUInt32, x)))
661#define CPL_SWAP64(x) \
662 CPL_STATIC_CAST(GUInt64, __builtin_bswap64(CPL_STATIC_CAST(GUInt64, x)))
663#elif defined(_MSC_VER)
664#define CPL_SWAP32(x) \
665 CPL_STATIC_CAST(GUInt32, _byteswap_ulong(CPL_STATIC_CAST(GUInt32, x)))
666#define CPL_SWAP64(x) \
667 CPL_STATIC_CAST(GUInt64, _byteswap_uint64(CPL_STATIC_CAST(GUInt64, x)))
670#define CPL_SWAP32(x) \
671 CPL_STATIC_CAST(GUInt32, \
672 ((CPL_STATIC_CAST(GUInt32, x) & 0x000000ffU) << 24) | \
673 ((CPL_STATIC_CAST(GUInt32, x) & 0x0000ff00U) << 8) | \
674 ((CPL_STATIC_CAST(GUInt32, x) & 0x00ff0000U) >> 8) | \
675 ((CPL_STATIC_CAST(GUInt32, x) & 0xff000000U) >> 24))
678#define CPL_SWAP64(x) \
679 ((CPL_STATIC_CAST(GUInt64, CPL_SWAP32(CPL_STATIC_CAST(GUInt32, x))) \
681 (CPL_STATIC_CAST(GUInt64, \
682 CPL_SWAP32(CPL_STATIC_CAST( \
683 GUInt32, CPL_STATIC_CAST(GUInt64, x) >> 32)))))
688#define CPL_SWAP16PTR(x) \
693 memcpy(&_n16, _lx, 2); \
694 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || \
695 sizeof(*(x)) == 2); \
696 _n16 = CPL_SWAP16(_n16); \
697 memcpy(_lx, &_n16, 2); \
701#define CPL_SWAP32PTR(x) \
706 memcpy(&_n32, _lx, 4); \
707 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || \
708 sizeof(*(x)) == 4); \
709 _n32 = CPL_SWAP32(_n32); \
710 memcpy(_lx, &_n32, 4); \
714#define CPL_SWAP64PTR(x) \
719 memcpy(&_n64, _lx, 8); \
720 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || \
721 sizeof(*(x)) == 8); \
722 _n64 = CPL_SWAP64(_n64); \
723 memcpy(_lx, &_n64, 8); \
727#define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
730#define CPL_MSBWORD16(x) (x)
731#define CPL_LSBWORD16(x) CPL_SWAP16(x)
732#define CPL_MSBWORD32(x) (x)
733#define CPL_LSBWORD32(x) CPL_SWAP32(x)
734#define CPL_MSBPTR16(x) \
735 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
736#define CPL_LSBPTR16(x) CPL_SWAP16PTR(x)
737#define CPL_MSBPTR32(x) \
738 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
739#define CPL_LSBPTR32(x) CPL_SWAP32PTR(x)
740#define CPL_MSBPTR64(x) \
741 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
742#define CPL_LSBPTR64(x) CPL_SWAP64PTR(x)
745#define CPL_LSBWORD16(x) (x)
747#define CPL_MSBWORD16(x) CPL_SWAP16(x)
749#define CPL_LSBWORD32(x) (x)
751#define CPL_MSBWORD32(x) CPL_SWAP32(x)
754#define CPL_LSBPTR16(x) \
755 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
758#define CPL_MSBPTR16(x) CPL_SWAP16PTR(x)
761#define CPL_LSBPTR32(x) \
762 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
765#define CPL_MSBPTR32(x) CPL_SWAP32PTR(x)
768#define CPL_LSBPTR64(x) \
769 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
772#define CPL_MSBPTR64(x) CPL_SWAP64PTR(x)
778#define CPL_LSBINT16PTR(x) \
779 ((*CPL_REINTERPRET_CAST(const GByte *, x)) | \
780 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 1) << 8))
785#define CPL_LSBINT32PTR(x) \
786 ((*CPL_REINTERPRET_CAST(const GByte *, x)) | \
787 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 1) << 8) | \
788 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 2) << 16) | \
789 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 3) << 24))
792#define CPL_LSBSINT16PTR(x) CPL_STATIC_CAST(GInt16, CPL_LSBINT16PTR(x))
796#define CPL_LSBUINT16PTR(x) CPL_STATIC_CAST(GUInt16, CPL_LSBINT16PTR(x))
799#define CPL_LSBSINT32PTR(x) CPL_STATIC_CAST(GInt32, CPL_LSBINT32PTR(x))
803#define CPL_LSBUINT32PTR(x) CPL_STATIC_CAST(GUInt32, CPL_LSBINT32PTR(x))
805#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
814 template <
class T>
struct CPL_T_IsAlwaysFalse
816 static const bool value =
false;
828 static_assert(CPL_T_IsAlwaysFalse<T>::value,
"Unsupported value for T");
832 template <>
inline int8_t CPL_AS_LSB<int8_t>(int8_t x)
837 template <>
inline uint8_t CPL_AS_LSB<uint8_t>(uint8_t x)
842 template <>
inline int16_t CPL_AS_LSB<int16_t>(int16_t x)
848 template <>
inline uint16_t CPL_AS_LSB<uint16_t>(uint16_t x)
854 template <>
inline int32_t CPL_AS_LSB<int32_t>(int32_t x)
860 template <>
inline uint32_t CPL_AS_LSB<uint32_t>(uint32_t x)
866 template <>
inline int64_t CPL_AS_LSB<int64_t>(int64_t x)
872 template <>
inline uint64_t CPL_AS_LSB<uint64_t>(uint64_t x)
878 template <>
inline float CPL_AS_LSB<float>(
float x)
884 template <>
inline double CPL_AS_LSB<double>(
double x)
900 memcpy(&x, ptr,
sizeof(x));
911 static_assert(CPL_T_IsAlwaysFalse<T>::value,
"Unsupported value for T");
915 template <>
inline int8_t CPL_SWAP<int8_t>(int8_t x)
920 template <>
inline uint8_t CPL_SWAP<uint8_t>(uint8_t x)
925 template <>
inline uint16_t CPL_SWAP<uint16_t>(uint16_t x)
930 template <>
inline int16_t CPL_SWAP<int16_t>(int16_t x)
933 memcpy(&x, &ux,
sizeof(x));
937 template <>
inline uint32_t CPL_SWAP<uint32_t>(uint32_t x)
942 template <>
inline int32_t CPL_SWAP<int32_t>(int32_t x)
945 memcpy(&x, &ux,
sizeof(x));
949 template <>
inline uint64_t CPL_SWAP<uint64_t>(uint64_t x)
954 template <>
inline int64_t CPL_SWAP<int64_t>(int64_t x)
957 memcpy(&x, &ux,
sizeof(x));
961 template <>
inline float CPL_SWAP<float>(
float x)
968 template <>
inline double CPL_SWAP<double>(
double x)
981#ifndef UNREFERENCED_PARAM
982#ifdef UNREFERENCED_PARAMETER
983#define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param)
985#define UNREFERENCED_PARAM(param) ((void)param)
991#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) && \
992 !(defined(__MINGW64__) && __GNUC__ == 4 && __GNUC_MINOR__ == 6)
994#define CPL_NULL_TERMINATED __attribute__((__sentinel__))
997#define CPL_NULL_TERMINATED
1000#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
1002#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx) \
1003 __attribute__((__format__(__printf__, format_idx, arg_idx)))
1005#define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx) \
1006 __attribute__((__format__(__scanf__, format_idx, arg_idx)))
1009#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
1011#define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx)
1014#if defined(_MSC_VER) && \
1015 (defined(GDAL_COMPILATION) || defined(CPL_ENABLE_MSVC_ANNOTATIONS))
1019#define CPL_FORMAT_STRING(arg) _Printf_format_string_ arg
1022#define CPL_SCANF_FORMAT_STRING(arg) _Scanf_format_string_ arg
1025#define CPL_FORMAT_STRING(arg) arg
1027#define CPL_SCANF_FORMAT_STRING(arg) arg
1030#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
1032#define CPL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
1035#define CPL_WARN_UNUSED_RESULT
1038#if defined(__GNUC__) && __GNUC__ >= 4
1040#define CPL_UNUSED __attribute((__unused__))
1047#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
1050#define CPL_NO_RETURN __attribute__((noreturn))
1054#define CPL_NO_RETURN
1059#ifndef __has_attribute
1060#define __has_attribute(x) 0
1065#if ((defined(__GNUC__) && \
1066 (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))) || \
1067 __has_attribute(returns_nonnull)) && \
1068 !defined(DOXYGEN_SKIP) && !defined(__INTEL_COMPILER)
1070#define CPL_RETURNS_NONNULL __attribute__((returns_nonnull))
1073#define CPL_RETURNS_NONNULL
1076#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
1078#define CPL_RESTRICT __restrict__
1084#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
1088#define CPL_OVERRIDE override
1091#define CPL_FINAL final
1094#define CPL_NON_FINAL
1101#define CPL_DISALLOW_COPY_ASSIGN(ClassName) \
1102 ClassName(const ClassName &) = delete; \
1103 ClassName &operator=(const ClassName &) = delete;
1107#ifdef CPL_DISABLE_WARN_DEPRECATED
1108#define CPL_WARN_DEPRECATED(x)
1109#elif !defined(DOXYGEN_SKIP) && !defined(CPL_WARN_DEPRECATED)
1110#if defined(__has_extension)
1111#if __has_extension(attribute_deprecated_with_message)
1113#define CPL_WARN_DEPRECATED(x) __attribute__((deprecated(x)))
1115#define CPL_WARN_DEPRECATED(x)
1117#elif defined(__GNUC__)
1118#define CPL_WARN_DEPRECATED(x) __attribute__((deprecated))
1120#define CPL_WARN_DEPRECATED(x)
1124#if !defined(_MSC_VER) && !defined(__APPLE__) && !defined(_FORTIFY_SOURCE)
1126#if defined(GDAL_COMPILATION) && defined(WARN_STANDARD_PRINTF)
1127int vsnprintf(
char *str,
size_t size,
const char *fmt, va_list args)
1128 CPL_WARN_DEPRECATED(
"Use CPLvsnprintf() instead");
1129int snprintf(
char *str,
size_t size,
const char *fmt, ...)
1131 CPL_WARN_DEPRECATED("Use CPLsnprintf() instead");
1133 CPL_WARN_DEPRECATED("Use CPLsnprintf() instead");
1134#elif defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
1136 CPL_WARN_DEPRECATED("Use snprintf() or CPLsnprintf() instead");
1141#if defined(__cplusplus)
1144#define CPL_ARRAYSIZE(array) \
1145 ((sizeof(array) / sizeof(*(array))) / \
1146 static_cast<size_t>(!(sizeof(array) % sizeof(*(array)))))
1149#define CPL_ARRAYSIZE(array) (sizeof(array) / sizeof(array[0]))
1154 template <
class T>
static void CPL_IGNORE_RET_VAL(
const T &)
1158 inline static bool CPL_TO_BOOL(
int x)
1166#if (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || \
1167 (defined(__clang__) && __clang_major__ >= 3)) && \
1169#define HAVE_GCC_DIAGNOSTIC_PUSH
1172#if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) && \
1174#define HAVE_GCC_SYSTEM_HEADER
1187#if __clang_major__ >= 4 || (__clang_major__ == 3 && __clang_minor__ >= 8)
1188#define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW \
1189 __attribute__((no_sanitize("unsigned-integer-overflow")))
1191#define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
1194#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && \
1195 defined(GDAL_COMPILATION)
1198 template <
class C,
class A,
class B>
1199 CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
inline C CPLUnsanitizedAdd(A a, B b)
1206#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
1207#define CPL_NULLPTR nullptr
1209#define CPL_NULLPTR NULL
1212#if defined(__cplusplus) && defined(GDAL_COMPILATION)
1221 template <
typename T>
inline T fits_on(T t)
1227 template <
typename C,
typename V>
1228 inline bool contains(
const C &container,
const V &value)
1230 return container.find(value) != container.end();
1244#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && \
1245 !defined(DOXYGEN_SKIP)
1255#if defined(__cplusplus) && defined(GDAL_COMPILATION)
1256#if defined(__GNUC__) && !defined(DOXYGEN_SKIP)
1260#define CPL_UNLIKELY(cond) __builtin_expect(static_cast<bool>(cond), 0)
1262#define CPL_UNLIKELY(cond) (cond)
#define CPL_LSBPTR64(x)
Byte-swap if necessary a 64bit word at the location pointed from a originally LSB ordered pointer.
Definition cpl_port.h:768
int GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition cpl_port.h:236
#define CPL_LSBPTR16(x)
Byte-swap if necessary a 16bit word at the location pointed from a originally LSB ordered pointer.
Definition cpl_port.h:754
#define CPL_SWAP64PTR(x)
Byte-swap a 64 bit pointer.
Definition cpl_port.h:714
#define CPL_SWAP32PTR(x)
Byte-swap a 32 bit pointer.
Definition cpl_port.h:701
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition cpl_port.h:198
short GInt16
Int16 type.
Definition cpl_port.h:161
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:279
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:275
#define CPL_LSBPTR32(x)
Byte-swap if necessary a 32bit word at the location pointed from a originally LSB ordered pointer.
Definition cpl_port.h:761
GIntBig GInt64
Signed 64 bit integer type.
Definition cpl_port.h:216
int GBool
Type for boolean values (alias to int)
Definition cpl_port.h:176
#define CPL_SWAP16(x)
Byte-swap a 16bit unsigned integer.
Definition cpl_port.h:652
#define CPL_SWAP32(x)
Byte-swap a 32bit unsigned integer.
Definition cpl_port.h:670
unsigned int GUInt32
Unsigned int32 type.
Definition cpl_port.h:157
#define CPL_SWAP64(x)
Byte-swap a 64bit unsigned integer.
Definition cpl_port.h:678
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition cpl_port.h:1009
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1252
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition cpl_port.h:218
unsigned short GUInt16
Unsigned int16 type.
Definition cpl_port.h:163
T CPL_SWAP(T)
Return the byte swapped version of the provided value.
Definition cpl_port.h:908
unsigned char GByte
Unsigned byte type.
Definition cpl_port.h:165
T CPL_AS_LSB(T)
Return the provided value as a LSB ordered one.
Definition cpl_port.h:825
T CPL_FROM_LSB(const void *ptr)
Return a primitive type from a memory buffer containing its LSB ordered byte sequence.
Definition cpl_port.h:897
int GInt32
Int32 type.
Definition cpl_port.h:155
signed char GInt8
Signed int8 type.
Definition cpl_port.h:167
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:195