- Main Page
- Classes
- Files
- Related Pages

- File List
- File Members

# cpl_port.h

Go to the documentation of this file.

    00001 /******************************************************************************
    00002  * $Id: cpl_port.h 10646 2007-01-18 02:38:10Z warmerdam $
    00003  *
    00004  * Project:  CPL - Common Portability Library
    00005  * Author:   Frank Warmerdam, warmerdam@pobox.com
    00006  * Purpose:  Include file providing low level portability services for CPL.
    00007  *           This should be the first include file for any CPL based code.
    00008  *
    00009  ******************************************************************************
    00010  * Copyright (c) 1998, 2005, Frank Warmerdam <warmerdam@pobox.com>
    00011  *
    00012  * Permission is hereby granted, free of charge, to any person obtaining a
    00013  * copy of this software and associated documentation files (the "Software"),
    00014  * to deal in the Software without restriction, including without limitation
    00015  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    00016  * and/or sell copies of the Software, and to permit persons to whom the
    00017  * Software is furnished to do so, subject to the following conditions:
    00018  *
    00019  * The above copyright notice and this permission notice shall be included
    00020  * in all copies or substantial portions of the Software.
    00021  *
    00022  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    00023  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00024  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    00025  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00026  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    00027  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    00028  * DEALINGS IN THE SOFTWARE.
    00029  ****************************************************************************/
    00030
    00031 #ifndef CPL_BASE_H_INCLUDED
    00032 #define CPL_BASE_H_INCLUDED
    00033
    00034 /* Remove annoying warnings Microsoft Visual C++ */
    00035 #if defined(_MSC_VER)
    00036 #  pragma warning(disable:4251 4275 4786)
    00037 #endif
    00038
    00046 /* ==================================================================== */
    00047 /*      We will use macos_pre10 to indicate compilation with MacOS      */
    00048 /*      versions before MacOS X.                                        */
    00049 /* ==================================================================== */
    00050 #ifdef macintosh
    00051 #  define macos_pre10
    00052 #endif
    00053
    00054 /* ==================================================================== */
    00055 /*      We will use WIN32 as a standard windows define.                 */
    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 /*      We will use WIN32CE as a standard Windows CE (Mobile) define.   */
    00067 /* ==================================================================== */
    00068 #if defined(_WIN32_WCE)
    00069 #  define WIN32CE
    00070 #endif
    00071
    00072 /* -------------------------------------------------------------------- */
    00073 /*      The following apparently allow you to use strcpy() and other    */
    00074 /*      functions judged "unsafe" by microsoft in VS 8 (2005).          */
    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 /*      This will disable most WIN32 stuff in a Cygnus build which      */
    00090 /*      defines unix to 1.                                              */
    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 /*      Standard include files.                                         */
    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 /*      Base portability stuff ... this stuff may need to be            */
    00149 /*      modified for new platforms.                                     */
    00150 /* ==================================================================== */
    00151
    00152 /*---------------------------------------------------------------------
    00153  *        types for 16 and 32 bits integers, etc...
    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 /*      64bit support                                                   */
    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 /*      Other standard services.                                        */
    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 // Should optional (normally private) interfaces be exported?
    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 /*      Macro to test equality of two floating point values.            */
    00253 /*      We use fabs() function instead of ABS() macro to avoid side     */
    00254 /*      effects.                                                        */
    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 /*      Handle isnan() and isinf().  Note that isinf() and isnan()      */
    00282 /*      are supposed to be macros according to C99.  Some systems       */
    00283 /*      (ie. Tru64) don't have isinf() at all, so if the macro is       */
    00284 /*      not defined we just assume nothing is infinite.  This may       */
    00285 /*      mean we have no real CPLIsInf() on systems with an isinf()      */
    00286 /*      function but no corresponding macro, but I can live with        */
    00287 /*      that since it isn't that important a test.                      */
    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  *                         CPL_LSB and CPL_MSB
    00306  * Only one of these 2 macros should be defined and specifies the byte
    00307  * ordering for the current platform.
    00308  * This should be defined in the Makefile, but if it is not then
    00309  * the default is CPL_LSB (Intel ordering, LSB first).
    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  *        Little endian <==> big endian byte swap macros.
    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 /* Until we have a safe 64 bits integer data type defined, we'll replace
    00382 m * this version of the CPL_SWAP64() macro with a less efficient one.
    00383  */
    00384 /*
    00385 #define CPL_SWAP64(x) \
    00386         ((uint64)( \
    00387             (uint64)(((uint64)(x) & (uint64)0x00000000000000ffULL) << 56) | \
    00388             (uint64)(((uint64)(x) & (uint64)0x000000000000ff00ULL) << 40) | \
    00389             (uint64)(((uint64)(x) & (uint64)0x0000000000ff0000ULL) << 24) | \
    00390             (uint64)(((uint64)(x) & (uint64)0x00000000ff000000ULL) << 8) | \
    00391             (uint64)(((uint64)(x) & (uint64)0x000000ff00000000ULL) >> 8) | \
    00392             (uint64)(((uint64)(x) & (uint64)0x0000ff0000000000ULL) >> 24) | \
    00393             (uint64)(((uint64)(x) & (uint64)0x00ff000000000000ULL) >> 40) | \
    00394             (uint64)(((uint64)(x) & (uint64)0xff00000000000000ULL) >> 56) ))
    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  * Define CPL_CVSID() macro.  It can be disabled during a build by
    00425  * defining DISABLE_CPLID in the compiler options.
    00426  *
    00427  * The cvsid_aw() function is just there to prevent reports of cpl_cvsid()
    00428  * being unused.
    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 /* ndef CPL_BASE_H_INCLUDED */

Generated for GDAL by 1.5.1.