Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef CPL_BASE_H_INCLUDED
00033 #define CPL_BASE_H_INCLUDED
00034
00042
00043
00044
00045
00046 #ifdef macintosh
00047 # define macos_pre10
00048 #endif
00049
00050
00051
00052
00053 #if defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE)
00054 # define WIN32
00055 #endif
00056
00057 #if defined(_WINDOWS) && !defined(WIN32) && !defined(_WIN32_WCE)
00058 # define WIN32
00059 #endif
00060
00061
00062
00063
00064 #if defined(_WIN32_WCE)
00065 # define WIN32CE
00066 #endif
00067
00068
00069
00070
00071
00072 #ifdef _MSC_VER
00073 # ifndef _CRT_SECURE_NO_DEPRECATE
00074 # define _CRT_SECURE_NO_DEPRECATE
00075 # endif
00076 # ifndef _CRT_NONSTDC_NO_DEPRECATE
00077 # define _CRT_NONSTDC_NO_DEPRECATE
00078 # endif
00079 #endif
00080
00081 #include "cpl_config.h"
00082
00083
00084
00085
00086
00087
00088 #if !defined(SIZEOF_INT) || SIZEOF_INT != 4
00089 #error "Unexpected value for SIZEOF_INT"
00090 #endif
00091
00092 #if !defined(SIZEOF_UNSIGNED_LONG) || (SIZEOF_UNSIGNED_LONG != 4 && SIZEOF_UNSIGNED_LONG != 8)
00093 #error "Unexpected value for SIZEOF_UNSIGNED_LONG"
00094 #endif
00095
00096 #if !defined(SIZEOF_VOIDP) || (SIZEOF_VOIDP != 4 && SIZEOF_VOIDP != 8)
00097 #error "Unexpected value for SIZEOF_VOIDP"
00098 #endif
00099
00100
00101
00102
00103
00104
00105
00106 #ifdef unix
00107 # undef WIN32
00108 # undef WIN32CE
00109 #endif
00110
00111 #if defined(VSI_NEED_LARGEFILE64_SOURCE) && !defined(_LARGEFILE64_SOURCE)
00112 # define _LARGEFILE64_SOURCE 1
00113 #endif
00114
00115
00116
00117
00118
00119
00120
00121 #if defined(HAVE_ICONV)
00122 # define CPL_RECODE_ICONV
00123 #endif
00124
00125 #define CPL_RECODE_STUB
00126
00127
00128
00129
00130
00131
00132
00133
00134 #if defined(__MINGW32__)
00135 #ifndef __MSVCRT_VERSION__
00136 #define __MSVCRT_VERSION__ 0x0601
00137 #endif
00138 #endif
00139
00140
00141
00142
00143
00144 #include <stdio.h>
00145 #include <stdlib.h>
00146 #include <math.h>
00147 #include <stdarg.h>
00148 #include <string.h>
00149 #include <ctype.h>
00150 #include <limits.h>
00151
00152 #if !defined(WIN32CE)
00153 # include <time.h>
00154 #else
00155 # include <wce_time.h>
00156 # include <wce_errno.h>
00157 #endif
00158
00159
00160 #if defined(HAVE_ERRNO_H)
00161 # include <errno.h>
00162 #endif
00163
00164 #ifdef HAVE_LOCALE_H
00165 # include <locale.h>
00166 #endif
00167
00168 #ifdef HAVE_DIRECT_H
00169 # include <direct.h>
00170 #endif
00171
00172 #if !(defined(WIN32) || defined(WIN32CE))
00173 # include <strings.h>
00174 #endif
00175
00176 #if defined(HAVE_LIBDBMALLOC) && defined(HAVE_DBMALLOC_H) && defined(DEBUG)
00177 # define DBMALLOC
00178 # include <dbmalloc.h>
00179 #endif
00180
00181 #if !defined(DBMALLOC) && defined(HAVE_DMALLOC_H)
00182 # define USE_DMALLOC
00183 # include <dmalloc.h>
00184 #endif
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 #if UINT_MAX == 65535
00195 typedef long GInt32;
00196 typedef unsigned long GUInt32;
00197 #else
00198 typedef int GInt32;
00199 typedef unsigned int GUInt32;
00200 #endif
00201
00202 typedef short GInt16;
00203 typedef unsigned short GUInt16;
00204 typedef unsigned char GByte;
00205
00206
00207 #ifndef CPL_GBOOL_DEFINED
00208 #define CPL_GBOOL_DEFINED
00209 typedef int GBool;
00210 #endif
00211
00212
00213
00214
00215
00216 #if defined(WIN32) && defined(_MSC_VER)
00217
00218 #define VSI_LARGE_API_SUPPORTED
00219 typedef __int64 GIntBig;
00220 typedef unsigned __int64 GUIntBig;
00221
00222 #elif HAVE_LONG_LONG
00223
00224 typedef long long GIntBig;
00225 typedef unsigned long long GUIntBig;
00226
00227 #else
00228
00229 typedef long GIntBig;
00230 typedef unsigned long GUIntBig;
00231
00232 #endif
00233
00234 #if defined(__MSVCRT__) || (defined(WIN32) && defined(_MSC_VER))
00235 #define CPL_FRMT_GB_WITHOUT_PREFIX "I64"
00236 #elif HAVE_LONG_LONG
00237 #define CPL_FRMT_GB_WITHOUT_PREFIX "ll"
00238 #else
00239 #define CPL_FRMT_GB_WITHOUT_PREFIX "l"
00240 #endif
00241
00242 #define CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"
00243 #define CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"
00244
00245
00246 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
00247 #define GUINTBIG_TO_DOUBLE(x) (double)(GIntBig)(x)
00248 #else
00249 #define GUINTBIG_TO_DOUBLE(x) (double)(x)
00250 #endif
00251
00252
00253
00254
00255 #ifdef __cplusplus
00256 # define CPL_C_START extern "C" {
00257 # define CPL_C_END }
00258 #else
00259 # define CPL_C_START
00260 # define CPL_C_END
00261 #endif
00262
00263 #ifndef CPL_DLL
00264 #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
00265 # define CPL_DLL __declspec(dllexport)
00266 #else
00267 # if defined(USE_GCC_VISIBILITY_FLAG)
00268 # define CPL_DLL __attribute__ ((visibility("default")))
00269 # else
00270 # define CPL_DLL
00271 # endif
00272 #endif
00273 #endif
00274
00275
00276 #ifdef CPL_OPTIONAL_APIS
00277 # define CPL_ODLL CPL_DLL
00278 #else
00279 # define CPL_ODLL
00280 #endif
00281
00282 #ifndef CPL_STDCALL
00283 #if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL)
00284 # define CPL_STDCALL __stdcall
00285 #else
00286 # define CPL_STDCALL
00287 #endif
00288 #endif
00289
00290 #ifdef _MSC_VER
00291 # define FORCE_CDECL __cdecl
00292 #else
00293 # define FORCE_CDECL
00294 #endif
00295
00296
00297 #if defined(__GNUC__) || defined(_MSC_VER)
00298 #define HAS_CPL_INLINE 1
00299 #define CPL_INLINE __inline
00300 #elif defined(__SUNPRO_CC)
00301 #define HAS_CPL_INLINE 1
00302 #define CPL_INLINE inline
00303 #else
00304 #define CPL_INLINE
00305 #endif
00306
00307 #ifndef NULL
00308 # define NULL 0
00309 #endif
00310
00311 #ifndef FALSE
00312 # define FALSE 0
00313 #endif
00314
00315 #ifndef TRUE
00316 # define TRUE 1
00317 #endif
00318
00319 #ifndef MAX
00320 # define MIN(a,b) ((a<b) ? a : b)
00321 # define MAX(a,b) ((a>b) ? a : b)
00322 #endif
00323
00324 #ifndef ABS
00325 # define ABS(x) ((x<0) ? (-1*(x)) : x)
00326 #endif
00327
00328 #ifndef M_PI
00329 # define M_PI 3.14159265358979323846
00330 #endif
00331
00332
00333
00334
00335
00336
00337 #ifndef CPLIsEqual
00338 # define CPLIsEqual(x,y) (fabs((x) - (y)) < 0.0000000000001)
00339 #endif
00340
00341
00342
00343
00344 #ifndef EQUAL
00345 # if defined(WIN32) || defined(WIN32CE)
00346 # define STRCASECMP(a,b) (stricmp(a,b))
00347 # define STRNCASECMP(a,b,n) (strnicmp(a,b,n))
00348 # else
00349 # define STRCASECMP(a,b) (strcasecmp(a,b))
00350 # define STRNCASECMP(a,b,n) (strncasecmp(a,b,n))
00351 # endif
00352 # define EQUALN(a,b,n) (STRNCASECMP(a,b,n)==0)
00353 # define EQUAL(a,b) (STRCASECMP(a,b)==0)
00354 #endif
00355
00356 #ifdef macos_pre10
00357 int strcasecmp(char * str1, char * str2);
00358 int strncasecmp(char * str1, char * str2, int len);
00359 char * strdup (char *instr);
00360 #endif
00361
00362 #ifndef CPL_THREADLOCAL
00363 # define CPL_THREADLOCAL
00364 #endif
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375 #ifdef _MSC_VER
00376 # include <float.h>
00377 # define CPLIsNan(x) _isnan(x)
00378 # define CPLIsInf(x) (!_isnan(x) && !_finite(x))
00379 # define CPLIsFinite(x) _finite(x)
00380 #else
00381 # define CPLIsNan(x) isnan(x)
00382 # ifdef isinf
00383 # define CPLIsInf(x) isinf(x)
00384 # define CPLIsFinite(x) (!isnan(x) && !isinf(x))
00385 # else
00386 # define CPLIsInf(x) FALSE
00387 # define CPLIsFinite(x) (!isnan(x))
00388 # endif
00389 #endif
00390
00391
00392
00393
00394
00395
00396
00397
00398 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
00399 # define CPL_MSB
00400 #endif
00401
00402 #if ! ( defined(CPL_LSB) || defined(CPL_MSB) )
00403 #define CPL_LSB
00404 #endif
00405
00406 #if defined(CPL_LSB)
00407 # define CPL_IS_LSB 1
00408 #else
00409 # define CPL_IS_LSB 0
00410 #endif
00411
00412
00413
00414
00415
00416 #define CPL_SWAP16(x) \
00417 ((GUInt16)( \
00418 (((GUInt16)(x) & 0x00ffU) << 8) | \
00419 (((GUInt16)(x) & 0xff00U) >> 8) ))
00420
00421 #define CPL_SWAP16PTR(x) \
00422 { \
00423 GByte byTemp, *_pabyDataT = (GByte *) (x); \
00424 \
00425 byTemp = _pabyDataT[0]; \
00426 _pabyDataT[0] = _pabyDataT[1]; \
00427 _pabyDataT[1] = byTemp; \
00428 }
00429
00430 #define CPL_SWAP32(x) \
00431 ((GUInt32)( \
00432 (((GUInt32)(x) & (GUInt32)0x000000ffUL) << 24) | \
00433 (((GUInt32)(x) & (GUInt32)0x0000ff00UL) << 8) | \
00434 (((GUInt32)(x) & (GUInt32)0x00ff0000UL) >> 8) | \
00435 (((GUInt32)(x) & (GUInt32)0xff000000UL) >> 24) ))
00436
00437 #define CPL_SWAP32PTR(x) \
00438 { \
00439 GByte byTemp, *_pabyDataT = (GByte *) (x); \
00440 \
00441 byTemp = _pabyDataT[0]; \
00442 _pabyDataT[0] = _pabyDataT[3]; \
00443 _pabyDataT[3] = byTemp; \
00444 byTemp = _pabyDataT[1]; \
00445 _pabyDataT[1] = _pabyDataT[2]; \
00446 _pabyDataT[2] = byTemp; \
00447 }
00448
00449 #define CPL_SWAP64PTR(x) \
00450 { \
00451 GByte byTemp, *_pabyDataT = (GByte *) (x); \
00452 \
00453 byTemp = _pabyDataT[0]; \
00454 _pabyDataT[0] = _pabyDataT[7]; \
00455 _pabyDataT[7] = byTemp; \
00456 byTemp = _pabyDataT[1]; \
00457 _pabyDataT[1] = _pabyDataT[6]; \
00458 _pabyDataT[6] = byTemp; \
00459 byTemp = _pabyDataT[2]; \
00460 _pabyDataT[2] = _pabyDataT[5]; \
00461 _pabyDataT[5] = byTemp; \
00462 byTemp = _pabyDataT[3]; \
00463 _pabyDataT[3] = _pabyDataT[4]; \
00464 _pabyDataT[4] = byTemp; \
00465 }
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484 #define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
00485
00486 #ifdef CPL_MSB
00487 # define CPL_MSBWORD16(x) (x)
00488 # define CPL_LSBWORD16(x) CPL_SWAP16(x)
00489 # define CPL_MSBWORD32(x) (x)
00490 # define CPL_LSBWORD32(x) CPL_SWAP32(x)
00491 # define CPL_MSBPTR16(x)
00492 # define CPL_LSBPTR16(x) CPL_SWAP16PTR(x)
00493 # define CPL_MSBPTR32(x)
00494 # define CPL_LSBPTR32(x) CPL_SWAP32PTR(x)
00495 # define CPL_MSBPTR64(x)
00496 # define CPL_LSBPTR64(x) CPL_SWAP64PTR(x)
00497 #else
00498 # define CPL_LSBWORD16(x) (x)
00499 # define CPL_MSBWORD16(x) CPL_SWAP16(x)
00500 # define CPL_LSBWORD32(x) (x)
00501 # define CPL_MSBWORD32(x) CPL_SWAP32(x)
00502 # define CPL_LSBPTR16(x)
00503 # define CPL_MSBPTR16(x) CPL_SWAP16PTR(x)
00504 # define CPL_LSBPTR32(x)
00505 # define CPL_MSBPTR32(x) CPL_SWAP32PTR(x)
00506 # define CPL_LSBPTR64(x)
00507 # define CPL_MSBPTR64(x) CPL_SWAP64PTR(x)
00508 #endif
00509
00511 #define CPL_LSBINT16PTR(x) ((*(GByte*)(x)) | ((*(GByte*)((x)+1)) << 8))
00512
00514 #define CPL_LSBINT32PTR(x) ((*(GByte*)(x)) | ((*(GByte*)((x)+1)) << 8) | \
00515 ((*(GByte*)((x)+2)) << 16) | ((*(GByte*)((x)+3)) << 24))
00516
00518 #define CPL_LSBSINT16PTR(x) ((GInt16) CPL_LSBINT16PTR(x))
00519
00521 #define CPL_LSBUINT16PTR(x) ((GUInt16)CPL_LSBINT16PTR(x))
00522
00524 #define CPL_LSBSINT32PTR(x) ((GInt32) CPL_LSBINT32PTR(x))
00525
00527 #define CPL_LSBUINT32PTR(x) ((GUInt32)CPL_LSBINT32PTR(x))
00528
00529
00530
00531 #ifndef UNREFERENCED_PARAM
00532 # ifdef UNREFERENCED_PARAMETER
00533 # define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param)
00534 # else
00535 # define UNREFERENCED_PARAM(param) ((void)param)
00536 # endif
00537 #endif
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547 #ifndef DISABLE_CVSID
00548 #if defined(__GNUC__) && __GNUC__ >= 4
00549 # define CPL_CVSID(string) static char cpl_cvsid[] __attribute__((used)) = string;
00550 #else
00551 # define CPL_CVSID(string) static char cpl_cvsid[] = string; \
00552 static char *cvsid_aw() { return( cvsid_aw() ? ((char *) NULL) : cpl_cvsid ); }
00553 #endif
00554 #else
00555 # define CPL_CVSID(string)
00556 #endif
00557
00558
00559 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
00560 # define CPL_NULL_TERMINATED __attribute__((__sentinel__))
00561 #else
00562 # define CPL_NULL_TERMINATED
00563 #endif
00564
00565 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
00566 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx)))
00567 #else
00568 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx )
00569 #endif
00570
00571 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
00572 #define CPL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
00573 #else
00574 #define CPL_WARN_UNUSED_RESULT
00575 #endif
00576
00577 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
00578 #define CPL_NO_RETURN __attribute__((noreturn))
00579 #else
00580 #define CPL_NO_RETURN
00581 #endif
00582
00583 #if !defined(DOXYGEN_SKIP)
00584 #if defined(__has_extension)
00585 #if __has_extension(attribute_deprecated_with_message)
00586
00587 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated(x)))
00588 #else
00589 #define CPL_WARN_DEPRECATED(x)
00590 #endif
00591 #elif defined(__GNUC__)
00592 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated))
00593 #else
00594 #define CPL_WARN_DEPRECATED(x)
00595 #endif
00596 #endif
00597
00598 #endif