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