SDTS_AL
Macros | Typedefs
cpl_port.h File Reference
#include "cpl_config.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <time.h>
#include <errno.h>
#include <locale.h>
#include <strings.h>

Go to the source code of this file.

Macros

#define GINTBIG_MIN   ((GIntBig)(0x80000000) << 32)
 
#define GINTBIG_MAX   (((GIntBig)(0x7FFFFFFF) << 32) | 0xFFFFFFFFU)
 
#define GUINTBIG_MAX   (((GUIntBig)(0xFFFFFFFFU) << 32) | 0xFFFFFFFFU)
 
#define GINT64_MIN   GINTBIG_MIN
 
#define GINT64_MAX   GINTBIG_MAX
 
#define GUINT64_MAX   GUINTBIG_MAX
 
#define CPL_FRMT_GB_WITHOUT_PREFIX   "ll"
 
#define CPL_FRMT_GIB   "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"
 
#define CPL_FRMT_GUIB   "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"
 
#define MIN(a, b)   (((a)<(b)) ? (a) : (b))
 
#define MAX(a, b)   (((a)>(b)) ? (a) : (b))
 
#define ABS(x)   (((x)<0) ? (-1*(x)) : (x))
 
#define M_PI   3.14159265358979323846
 
#define STRCASECMP(a, b)   (strcasecmp(a,b))
 
#define STRNCASECMP(a, b, n)   (strncasecmp(a,b,n))
 
#define EQUALN(a, b, n)   (STRNCASECMP(a,b,n)==0)
 
#define EQUAL(a, b)   (STRCASECMP(a,b)==0)
 
#define STARTS_WITH(a, b)   (strncmp(a,b,strlen(b)) == 0)
 
#define STARTS_WITH_CI(a, b)   EQUALN(a,b,strlen(b))
 
#define CPLIsNan(x)   isnan(x)
 
#define CPL_SWAP16(x)   ((GUInt16)( ((GUInt16)(x) << 8) | ((GUInt16)(x) >> 8) ))
 
#define CPL_SWAP32(x)
 
#define CPL_SWAP64(x)
 
#define CPL_SWAP16PTR(x)
 
#define CPL_SWAP32PTR(x)
 
#define CPL_SWAP64PTR(x)
 
#define CPL_SWAPDOUBLE(p)   CPL_SWAP64PTR(p)
 
#define CPL_LSBWORD16(x)   (x)
 
#define CPL_MSBWORD16(x)   CPL_SWAP16(x)
 
#define CPL_LSBWORD32(x)   (x)
 
#define CPL_MSBWORD32(x)   CPL_SWAP32(x)
 
#define CPL_LSBPTR16(x)   CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
 
#define CPL_MSBPTR16(x)   CPL_SWAP16PTR(x)
 
#define CPL_LSBPTR32(x)   CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
 
#define CPL_MSBPTR32(x)   CPL_SWAP32PTR(x)
 
#define CPL_LSBPTR64(x)   CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
 
#define CPL_MSBPTR64(x)   CPL_SWAP64PTR(x)
 
#define CPL_LSBINT16PTR(x)   ((*(GByte*)(x)) | (*(((GByte*)(x))+1) << 8))
 
#define CPL_LSBINT32PTR(x)
 
#define CPL_LSBSINT16PTR(x)   ((GInt16) CPL_LSBINT16PTR(x))
 
#define CPL_LSBUINT16PTR(x)   ((GUInt16)CPL_LSBINT16PTR(x))
 
#define CPL_LSBSINT32PTR(x)   ((GInt32) CPL_LSBINT32PTR(x))
 
#define CPL_LSBUINT32PTR(x)   ((GUInt32)CPL_LSBINT32PTR(x))
 
#define CPL_NULL_TERMINATED
 
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
 
#define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx)
 
#define CPL_FORMAT_STRING(arg)   arg
 
#define CPL_SCANF_FORMAT_STRING(arg)   arg
 
#define CPL_WARN_UNUSED_RESULT
 
#define CPL_UNUSED
 
#define CPL_NO_RETURN
 
#define CPL_RETURNS_NONNULL
 
#define CPL_RESTRICT
 
#define CPL_FALLTHROUGH
 

Typedefs

typedef int GInt32
 
typedef unsigned int GUInt32
 
typedef short GInt16
 
typedef unsigned short GUInt16
 
typedef unsigned char GByte
 
typedef int GBool
 
typedef long long GIntBig
 
typedef unsigned long long GUIntBig
 
typedef GIntBig GInt64
 
typedef GUIntBig GUInt64
 
typedef GIntBig GPtrDiff_t
 

Detailed Description

Core portability definitions for CPL.

Macro Definition Documentation

◆ ABS

#define ABS (   x)    (((x)<0) ? (-1*(x)) : (x))

Macro to compute the absolute value

◆ CPL_FALLTHROUGH

#define CPL_FALLTHROUGH

Macro for fallthrough in a switch case construct

◆ CPL_FORMAT_STRING

#define CPL_FORMAT_STRING (   arg)    arg

Macro into which to wrap the format argument of a printf-like function

◆ CPL_FRMT_GB_WITHOUT_PREFIX

#define CPL_FRMT_GB_WITHOUT_PREFIX   "ll"

Printf formatting suffix for GIntBig

◆ CPL_FRMT_GIB

#define CPL_FRMT_GIB   "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"

Printf formatting for GIntBig

◆ CPL_FRMT_GUIB

#define CPL_FRMT_GUIB   "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"

Printf formatting for GUIntBig

◆ CPL_LSBINT16PTR

#define CPL_LSBINT16PTR (   x)    ((*(GByte*)(x)) | (*(((GByte*)(x))+1) << 8))

Return a Int16 from the 2 bytes ordered in LSB order at address x.

Deprecated:
Use rather CPL_LSBSINT16PTR or CPL_LSBUINT16PTR for explicit signedness.

◆ CPL_LSBINT32PTR

#define CPL_LSBINT32PTR (   x)
Value:
((*(GByte*)(x)) | (*(((GByte*)(x))+1) << 8) | \
(*(((GByte*)(x))+2) << 16) | (*(((GByte*)(x))+3) << 24))
unsigned char GByte
Definition: cpl_port.h:207

Return a Int32 from the 4 bytes ordered in LSB order at address x.

Deprecated:
Use rather CPL_LSBSINT32PTR or CPL_LSBUINT32PTR for explicit signedness.

◆ CPL_LSBPTR16

#define CPL_LSBPTR16 (   x)    CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)

Byte-swap if necessary a 16bit word at the location pointed from a originally LSB ordered pointer

◆ CPL_LSBPTR32

#define CPL_LSBPTR32 (   x)    CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)

Byte-swap if necessary a 32bit word at the location pointed from a originally LSB ordered pointer

◆ CPL_LSBPTR64

#define CPL_LSBPTR64 (   x)    CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)

Byte-swap if necessary a 64bit word at the location pointed from a originally LSB ordered pointer

◆ CPL_LSBSINT16PTR

#define CPL_LSBSINT16PTR (   x)    ((GInt16) CPL_LSBINT16PTR(x))

Return a signed Int16 from the 2 bytes ordered in LSB order at address x

◆ CPL_LSBSINT32PTR

#define CPL_LSBSINT32PTR (   x)    ((GInt32) CPL_LSBINT32PTR(x))

Return a signed Int32 from the 4 bytes ordered in LSB order at address x

◆ CPL_LSBUINT16PTR

#define CPL_LSBUINT16PTR (   x)    ((GUInt16)CPL_LSBINT16PTR(x))

Return a unsigned Int16 from the 2 bytes ordered in LSB order at address x

◆ CPL_LSBUINT32PTR

#define CPL_LSBUINT32PTR (   x)    ((GUInt32)CPL_LSBINT32PTR(x))

Return a unsigned Int32 from the 4 bytes ordered in LSB order at address x

◆ CPL_LSBWORD16

#define CPL_LSBWORD16 (   x)    (x)

Return a 16bit word from a originally LSB ordered word

◆ CPL_LSBWORD32

#define CPL_LSBWORD32 (   x)    (x)

Return a 32bit word from a originally LSB ordered word

◆ CPL_MSBPTR16

#define CPL_MSBPTR16 (   x)    CPL_SWAP16PTR(x)

Byte-swap if necessary a 16bit word at the location pointed from a originally MSB ordered pointer

◆ CPL_MSBPTR32

#define CPL_MSBPTR32 (   x)    CPL_SWAP32PTR(x)

Byte-swap if necessary a 32bit word at the location pointed from a originally MSB ordered pointer

◆ CPL_MSBPTR64

#define CPL_MSBPTR64 (   x)    CPL_SWAP64PTR(x)

Byte-swap if necessary a 64bit word at the location pointed from a originally MSB ordered pointer

◆ CPL_MSBWORD16

#define CPL_MSBWORD16 (   x)    CPL_SWAP16(x)

Return a 16bit word from a originally MSB ordered word

◆ CPL_MSBWORD32

#define CPL_MSBWORD32 (   x)    CPL_SWAP32(x)

Return a 32bit word from a originally MSB ordered word

◆ CPL_NO_RETURN

#define CPL_NO_RETURN

Qualifier for a function that does not return at all (terminates the process)

◆ CPL_NULL_TERMINATED

#define CPL_NULL_TERMINATED

Null terminated variadic

◆ CPL_PRINT_FUNC_FORMAT

#define CPL_PRINT_FUNC_FORMAT (   format_idx,
  arg_idx 
)

Tag a function to have printf() formatting

◆ CPL_RESTRICT

#define CPL_RESTRICT

restrict keyword to declare that pointers do not alias

◆ CPL_RETURNS_NONNULL

#define CPL_RETURNS_NONNULL

Qualifier for a function that does not return NULL

◆ CPL_SCAN_FUNC_FORMAT

#define CPL_SCAN_FUNC_FORMAT (   format_idx,
  arg_idx 
)

Tag a function to have scanf() formatting

◆ CPL_SCANF_FORMAT_STRING

#define CPL_SCANF_FORMAT_STRING (   arg)    arg

Macro into which to wrap the format argument of a sscanf-like function.

◆ CPL_SWAP16

#define CPL_SWAP16 (   x)    ((GUInt16)( ((GUInt16)(x) << 8) | ((GUInt16)(x) >> 8) ))

Byte-swap a 16bit unsigned integer

◆ CPL_SWAP16PTR

#define CPL_SWAP16PTR (   x)
Value:
{ \
GByte byTemp, *_pabyDataT = (GByte *) (x); \
CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2); \
\
byTemp = _pabyDataT[0]; \
_pabyDataT[0] = _pabyDataT[1]; \
_pabyDataT[1] = byTemp; \
}
unsigned char GByte
Definition: cpl_port.h:207

Byte-swap a 16 bit pointer

◆ CPL_SWAP32

#define CPL_SWAP32 (   x)
Value:
((GUInt32)( \
(((GUInt32)(x) & (GUInt32)0x000000ffUL) << 24) | \
(((GUInt32)(x) & (GUInt32)0x0000ff00UL) << 8) | \
(((GUInt32)(x) & (GUInt32)0x00ff0000UL) >> 8) | \
(((GUInt32)(x) & (GUInt32)0xff000000UL) >> 24) ))
unsigned int GUInt32
Definition: cpl_port.h:199

Byte-swap a 32bit unsigned integer

◆ CPL_SWAP32PTR

#define CPL_SWAP32PTR (   x)
Value:
{ \
GByte byTemp, *_pabyDataT = (GByte *) (x); \
CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4); \
\
byTemp = _pabyDataT[0]; \
_pabyDataT[0] = _pabyDataT[3]; \
_pabyDataT[3] = byTemp; \
byTemp = _pabyDataT[1]; \
_pabyDataT[1] = _pabyDataT[2]; \
_pabyDataT[2] = byTemp; \
}
unsigned char GByte
Definition: cpl_port.h:207

Byte-swap a 32 bit pointer

◆ CPL_SWAP64

#define CPL_SWAP64 (   x)
Value:
(((GUInt64)(CPL_SWAP32((GUInt32)(x))) << 32) | \
(GUInt64)(CPL_SWAP32((GUInt32)((GUInt64)(x) >> 32))))
#define CPL_SWAP32(x)
Definition: cpl_port.h:772
unsigned int GUInt32
Definition: cpl_port.h:199
GUIntBig GUInt64
Definition: cpl_port.h:271

Byte-swap a 64bit unsigned integer

◆ CPL_SWAP64PTR

#define CPL_SWAP64PTR (   x)
Value:
{ \
GByte byTemp, *_pabyDataT = (GByte *) (x); \
CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8); \
\
byTemp = _pabyDataT[0]; \
_pabyDataT[0] = _pabyDataT[7]; \
_pabyDataT[7] = byTemp; \
byTemp = _pabyDataT[1]; \
_pabyDataT[1] = _pabyDataT[6]; \
_pabyDataT[6] = byTemp; \
byTemp = _pabyDataT[2]; \
_pabyDataT[2] = _pabyDataT[5]; \
_pabyDataT[5] = byTemp; \
byTemp = _pabyDataT[3]; \
_pabyDataT[3] = _pabyDataT[4]; \
_pabyDataT[4] = byTemp; \
}
unsigned char GByte
Definition: cpl_port.h:207

Byte-swap a 64 bit pointer

◆ CPL_SWAPDOUBLE

#define CPL_SWAPDOUBLE (   p)    CPL_SWAP64PTR(p)

Byte-swap a 64 bit pointer

◆ CPL_UNUSED

#define CPL_UNUSED

Qualifier for an argument that is unused

◆ CPL_WARN_UNUSED_RESULT

char CPL_DLL CPL_WARN_UNUSED_RESULT

Qualifier to warn when the return value of a function is not used

◆ CPLIsNan

#define CPLIsNan (   x)    isnan(x)

Return whether a floating-pointer number is NaN

◆ EQUAL

#define EQUAL (   a,
 
)    (STRCASECMP(a,b)==0)

Alias for strcasecmp() == 0

◆ EQUALN

#define EQUALN (   a,
  b,
 
)    (STRNCASECMP(a,b,n)==0)

Alias for strncasecmp() == 0

◆ GINT64_MAX

#define GINT64_MAX   GINTBIG_MAX

Maximum GInt64 value

◆ GINT64_MIN

#define GINT64_MIN   GINTBIG_MIN

Minimum GInt64 value

◆ GINTBIG_MAX

#define GINTBIG_MAX   (((GIntBig)(0x7FFFFFFF) << 32) | 0xFFFFFFFFU)

Maximum GIntBig value

◆ GINTBIG_MIN

#define GINTBIG_MIN   ((GIntBig)(0x80000000) << 32)

Minimum GIntBig value

◆ GUINT64_MAX

#define GUINT64_MAX   GUINTBIG_MAX

Minimum GUInt64 value

◆ GUINTBIG_MAX

#define GUINTBIG_MAX   (((GUIntBig)(0xFFFFFFFFU) << 32) | 0xFFFFFFFFU)

Maximum GUIntBig value

◆ M_PI

#define M_PI   3.14159265358979323846

PI definition

◆ MAX

#define MAX (   a,
 
)    (((a)>(b)) ? (a) : (b))

Macro to compute the maximum of 2 values

◆ MIN

#define MIN (   a,
 
)    (((a)<(b)) ? (a) : (b))

Macro to compute the minimum of 2 values

◆ STARTS_WITH

#define STARTS_WITH (   a,
 
)    (strncmp(a,b,strlen(b)) == 0)

Returns whether a starts with b

◆ STARTS_WITH_CI

#define STARTS_WITH_CI (   a,
 
)    EQUALN(a,b,strlen(b))

Returns whether a starts with b (case insensitive comparison)

◆ STRCASECMP

#define STRCASECMP (   a,
 
)    (strcasecmp(a,b))

Alias for strcasecmp()

◆ STRNCASECMP

#define STRNCASECMP (   a,
  b,
 
)    (strncasecmp(a,b,n))

Alias for strncasecmp()

Typedef Documentation

◆ GBool

typedef int GBool

Type for boolean values (alias to int)

◆ GByte

typedef unsigned char GByte

Unsigned byte type

◆ GInt16

typedef short GInt16

Int16 type

◆ GInt32

typedef int GInt32

Int32 type

◆ GInt64

typedef GIntBig GInt64

Signed 64 bit integer type

◆ GIntBig

typedef long long GIntBig

Large signed integer type (generally 64-bit integer type). Use GInt64 when exactly 64 bit is needed

◆ GPtrDiff_t

Integer type large enough to hold the difference between 2 addresses

◆ GUInt16

typedef unsigned short GUInt16

Unsigned int16 type

◆ GUInt32

typedef unsigned int GUInt32

Unsigned int32 type

◆ GUInt64

typedef GUIntBig GUInt64

Unsigned 64 bit integer type

◆ GUIntBig

typedef unsigned long long GUIntBig

Large unsigned integer type (generally 64-bit unsigned integer type). Use GUInt64 when exactly 64 bit is needed