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