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