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