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