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