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
00091
00092
00093
00094
00095
00096
00097 #ifndef CPL_BASE_H_INCLUDED
00098 #define CPL_BASE_H_INCLUDED
00099
00107
00108
00109
00110
00111 #ifdef macintosh
00112 # define macos_pre10
00113 #endif
00114
00115
00116
00117
00118 #if defined(_WIN32) && !defined(WIN32)
00119 # define WIN32
00120 #endif
00121
00122 #if defined(_WINDOWS) && !defined(WIN32)
00123 # define WIN32
00124 #endif
00125
00126 #include "cpl_config.h"
00127
00128
00129
00130
00131
00132
00133 #ifdef unix
00134 # undef WIN32
00135 #endif
00136
00137 #if defined(VSI_NEED_LARGEFILE64_SOURCE) && !defined(_LARGEFILE64_SOURCE)
00138 # define _LARGEFILE64_SOURCE 1
00139 #endif
00140
00141
00142
00143
00144
00145 #include <stdio.h>
00146 #include <stdlib.h>
00147 #include <math.h>
00148 #include <stdarg.h>
00149 #include <string.h>
00150 #include <ctype.h>
00151 #include <errno.h>
00152 #include <time.h>
00153
00154 #ifdef HAVE_LOCALE_H
00155 # include <locale.h>
00156 #endif
00157
00158 #ifdef _AIX
00159 # include <strings.h>
00160 #endif
00161
00162 #if defined(HAVE_LIBDBMALLOC) && defined(HAVE_DBMALLOC_H) && defined(DEBUG)
00163 # define DBMALLOC
00164 # include <dbmalloc.h>
00165 #endif
00166
00167 #if !defined(DBMALLOC) && defined(HAVE_DMALLOC_H)
00168 # define USE_DMALLOC
00169 # include <dmalloc.h>
00170 #endif
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 #if UINT_MAX == 65535
00181 typedef long GInt32;
00182 typedef unsigned long GUInt32;
00183 #else
00184 typedef int GInt32;
00185 typedef unsigned int GUInt32;
00186 #endif
00187
00188 typedef short GInt16;
00189 typedef unsigned short GUInt16;
00190 typedef unsigned char GByte;
00191 typedef int GBool;
00192
00193
00194
00195
00196
00197 #if defined(WIN32) && defined(_MSC_VER)
00198
00199 #define VSI_LARGE_API_SUPPORTED
00200 typedef __int64 GIntBig;
00201 typedef unsigned __int64 GUIntBig;
00202
00203 #elif HAVE_LONG_LONG
00204
00205 typedef long long GIntBig;
00206 typedef unsigned long long GUIntBig;
00207
00208 #else
00209
00210 typedef long GIntBig;
00211 typedef unsigned long GUIntBig;
00212
00213 #endif
00214
00215
00216
00217
00218 #ifdef __cplusplus
00219 # define CPL_C_START extern "C" {
00220 # define CPL_C_END }
00221 #else
00222 # define CPL_C_START
00223 # define CPL_C_END
00224 #endif
00225
00226 #ifndef CPL_DLL
00227 #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
00228 # define CPL_DLL __declspec(dllexport)
00229 #else
00230 # define CPL_DLL
00231 #endif
00232 #endif
00233
00234
00235 #ifndef NULL
00236 # define NULL 0
00237 #endif
00238
00239 #ifndef FALSE
00240 # define FALSE 0
00241 #endif
00242
00243 #ifndef TRUE
00244 # define TRUE 1
00245 #endif
00246
00247 #ifndef MAX
00248 # define MIN(a,b) ((a<b) ? a : b)
00249 # define MAX(a,b) ((a>b) ? a : b)
00250 #endif
00251
00252 #ifndef ABS
00253 # define ABS(x) ((x<0) ? (-1*(x)) : x)
00254 #endif
00255
00256 #ifndef EQUAL
00257 #ifdef WIN32
00258 # define EQUALN(a,b,n) (strnicmp(a,b,n)==0)
00259 # define EQUAL(a,b) (stricmp(a,b)==0)
00260 #else
00261 # define EQUALN(a,b,n) (strncasecmp(a,b,n)==0)
00262 # define EQUAL(a,b) (strcasecmp(a,b)==0)
00263 #endif
00264 #endif
00265
00266 #ifdef macos_pre10
00267 int strcasecmp(char * str1, char * str2);
00268 int strncasecmp(char * str1, char * str2, int len);
00269 char * strdup (char *instr);
00270 #endif
00271
00272
00273
00274
00275
00276
00277
00278
00279 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
00280 # define CPL_MSB
00281 #endif
00282
00283 #if ! ( defined(CPL_LSB) || defined(CPL_MSB) )
00284 #define CPL_LSB
00285 #endif
00286
00287
00288
00289
00290
00291 #define CPL_SWAP16(x) \
00292 ((GUInt16)( \
00293 (((GUInt16)(x) & 0x00ffU) << 8) | \
00294 (((GUInt16)(x) & 0xff00U) >> 8) ))
00295
00296 #define CPL_SWAP16PTR(x) \
00297 { \
00298 GByte byTemp, *_pabyDataT = (GByte *) (x); \
00299 \
00300 byTemp = _pabyDataT[0]; \
00301 _pabyDataT[0] = _pabyDataT[1]; \
00302 _pabyDataT[1] = byTemp; \
00303 }
00304
00305 #define CPL_SWAP32(x) \
00306 ((GUInt32)( \
00307 (((GUInt32)(x) & (GUInt32)0x000000ffUL) << 24) | \
00308 (((GUInt32)(x) & (GUInt32)0x0000ff00UL) << 8) | \
00309 (((GUInt32)(x) & (GUInt32)0x00ff0000UL) >> 8) | \
00310 (((GUInt32)(x) & (GUInt32)0xff000000UL) >> 24) ))
00311
00312 #define CPL_SWAP32PTR(x) \
00313 { \
00314 GByte byTemp, *_pabyDataT = (GByte *) (x); \
00315 \
00316 byTemp = _pabyDataT[0]; \
00317 _pabyDataT[0] = _pabyDataT[3]; \
00318 _pabyDataT[3] = byTemp; \
00319 byTemp = _pabyDataT[1]; \
00320 _pabyDataT[1] = _pabyDataT[2]; \
00321 _pabyDataT[2] = byTemp; \
00322 }
00323
00324 #define CPL_SWAP64PTR(x) \
00325 { \
00326 GByte byTemp, *_pabyDataT = (GByte *) (x); \
00327 \
00328 byTemp = _pabyDataT[0]; \
00329 _pabyDataT[0] = _pabyDataT[7]; \
00330 _pabyDataT[7] = byTemp; \
00331 byTemp = _pabyDataT[1]; \
00332 _pabyDataT[1] = _pabyDataT[6]; \
00333 _pabyDataT[6] = byTemp; \
00334 byTemp = _pabyDataT[2]; \
00335 _pabyDataT[2] = _pabyDataT[5]; \
00336 _pabyDataT[5] = byTemp; \
00337 byTemp = _pabyDataT[3]; \
00338 _pabyDataT[3] = _pabyDataT[4]; \
00339 _pabyDataT[4] = byTemp; \
00340 }
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 #define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
00360
00361 #ifdef CPL_MSB
00362 # define CPL_MSBWORD16(x) (x)
00363 # define CPL_LSBWORD16(x) CPL_SWAP16(x)
00364 # define CPL_MSBWORD32(x) (x)
00365 # define CPL_LSBWORD32(x) CPL_SWAP32(x)
00366 # define CPL_MSBPTR16(x)
00367 # define CPL_LSBPTR16(x) CPL_SWAP16PTR(x)
00368 # define CPL_MSBPTR32(x)
00369 # define CPL_LSBPTR32(x) CPL_SWAP32PTR(x)
00370 # define CPL_MSBPTR64(x)
00371 # define CPL_LSBPTR64(x) CPL_SWAP64PTR(x)
00372 #else
00373 # define CPL_LSBWORD16(x) (x)
00374 # define CPL_MSBWORD16(x) CPL_SWAP16(x)
00375 # define CPL_LSBWORD32(x) (x)
00376 # define CPL_MSBWORD32(x) CPL_SWAP32(x)
00377 # define CPL_LSBPTR16(x)
00378 # define CPL_MSBPTR16(x) CPL_SWAP16PTR(x)
00379 # define CPL_LSBPTR32(x)
00380 # define CPL_MSBPTR32(x) CPL_SWAP32PTR(x)
00381 # define CPL_LSBPTR64(x)
00382 # define CPL_MSBPTR64(x) CPL_SWAP64PTR(x)
00383 #endif
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393 #ifndef DISABLE_CVSID
00394 # define CPL_CVSID(string) static char cpl_cvsid[] = string; \
00395 static char *cvsid_aw() { return( cvsid_aw() ? ((char *) NULL) : cpl_cvsid ); }
00396 #else
00397 # define CPL_CVSID(string)
00398 #endif
00399
00400 #endif