- Main Page
- Classes
- Files
- Directories
- Related Pages

- File List
- File Members

# cpl_port.h

Go to the documentation of this file.

    00001 /******************************************************************************
    00002  * $Id: cpl_port.h,v 1.52 2006/04/19 01:59:18 fwarmerdam Exp $
    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  * $Log: cpl_port.h,v $
    00032  * Revision 1.52  2006/04/19 01:59:18  fwarmerdam
    00033  * move deprecate declarations before system include files
    00034  *
    00035  * Revision 1.51  2006/03/21 20:11:54  fwarmerdam
    00036  * fixup headers a bit
    00037  *
    00038  * Revision 1.50  2006/03/13 20:58:32  mloskot
    00039  * Test if macros _CRT_SECURE_NO_DEPRECATE and  _CRT_NONSTDC_NO_DEPRECATE
    00040  * are already defined, to get rid of warnings
    00041  *
    00042  * Revision 1.49  2006/02/20 01:03:01  fwarmerdam
    00043  * Fixed last change.
    00044  *
    00045  * Revision 1.48  2006/02/20 00:59:58  fwarmerdam
    00046  * Avoid deprecation of some common functions with VS8.
    00047  * http://bugzilla.remotesensing.org/show_bug.cgi?id=1083
    00048  *
    00049  * Revision 1.47  2006/02/19 21:54:34  mloskot
    00050  * [WINCE] Changes related to Windows CE port of CPL. Most changes are #ifdef wrappers.
    00051  *
    00052  * Revision 1.46  2005/12/08 20:21:10  fwarmerdam
    00053  * added CPL_ODLL declaration
    00054  *
    00055  * Revision 1.45  2005/06/15 09:47:40  dron
    00056  * Fixed typo.
    00057  *
    00058  * Revision 1.44  2005/06/15 09:11:58  dron
    00059  * Added CPLIsEqual() macro.
    00060  *
    00061  * Revision 1.43  2005/05/23 03:57:08  fwarmerdam
    00062  * added default definition of CPL_THREADLOCAL
    00063  *
    00064  * Revision 1.42  2005/04/04 15:22:36  fwarmerdam
    00065  * added CPL_STDCALL declaration
    00066  *
    00067  * Revision 1.41  2005/03/17 04:20:24  fwarmerdam
    00068  * added FORCE_CDECL
    00069  *
    00070  * Revision 1.40  2005/03/11 14:59:07  fwarmerdam
    00071  * Default to assuming nothing is infinite if isinf() macro not defined.
    00072  * Per http://bugzilla.remotesensing.org/show_bug.cgi?id=795
    00073  *
    00074  * Revision 1.39  2005/03/01 21:22:07  fwarmerdam
    00075  * added CPLIsFinite()
    00076  *
    00077  * Revision 1.38  2005/03/01 20:44:38  fwarmerdam
    00078  * Check for _MSC_VER instead of WIN32.
    00079  *
    00080  * Revision 1.37  2005/03/01 19:57:55  fwarmerdam
    00081  * Added CPLIsNan and CPLIsInf macros.
    00082  */
    00083
    00084 #ifndef CPL_BASE_H_INCLUDED
    00085 #define CPL_BASE_H_INCLUDED
    00086
    00094 /* ==================================================================== */
    00095 /*      We will use macos_pre10 to indicate compilation with MacOS      */
    00096 /*      versions before MacOS X.                                        */
    00097 /* ==================================================================== */
    00098 #ifdef macintosh
    00099 #  define macos_pre10
    00100 #endif
    00101
    00102 /* ==================================================================== */
    00103 /*      We will use WIN32 as a standard windows define.                 */
    00104 /* ==================================================================== */
    00105 #if defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE)
    00106 #  define WIN32
    00107 #endif
    00108
    00109 #if defined(_WINDOWS) && !defined(WIN32) && !defined(_WIN32_WCE)
    00110 #  define WIN32
    00111 #endif
    00112
    00113 /* ==================================================================== */
    00114 /*      We will use WIN32CE as a standard Windows CE (Mobile) define.   */
    00115 /* ==================================================================== */
    00116 #if defined(_WIN32_WCE)
    00117 #  define WIN32CE
    00118 #endif
    00119
    00120 /* -------------------------------------------------------------------- */
    00121 /*      The following apparently allow you to use strcpy() and other    */
    00122 /*      functions judged "unsafe" by microsoft in VS 8 (2005).          */
    00123 /* -------------------------------------------------------------------- */
    00124 #ifdef _MSC_VER
    00125 #  ifndef _CRT_SECURE_NO_DEPRECATE
    00126 #    define _CRT_SECURE_NO_DEPRECATE
    00127 #  endif
    00128 #  ifndef _CRT_NONSTDC_NO_DEPRECATE
    00129 #    define _CRT_NONSTDC_NO_DEPRECATE
    00130 #  endif
    00131 #endif
    00132
    00133
    00134 #include "cpl_config.h"
    00135
    00136 /* ==================================================================== */
    00137 /*      This will disable most WIN32 stuff in a Cygnus build which      */
    00138 /*      defines unix to 1.                                              */
    00139 /* ==================================================================== */
    00140
    00141 #ifdef unix
    00142 #  undef WIN32
    00143 #  undef WIN32CE
    00144 #endif
    00145
    00146 #if defined(VSI_NEED_LARGEFILE64_SOURCE) && !defined(_LARGEFILE64_SOURCE)
    00147 #  define _LARGEFILE64_SOURCE 1
    00148 #endif
    00149
    00150 /* ==================================================================== */
    00151 /*      Standard include files.                                         */
    00152 /* ==================================================================== */
    00153
    00154 #include <stdio.h>
    00155 #include <stdlib.h>
    00156 #include <math.h>
    00157 #include <stdarg.h>
    00158 #include <string.h>
    00159 #include <ctype.h>
    00160
    00161 #if !defined(WIN32CE)
    00162 #  include <time.h>
    00163 #else
    00164 #  include <wce_time.h>
    00165 #  include <wce_errno.h>
    00166 #endif
    00167
    00168
    00169 #if defined(HAVE_ERRNO_H)
    00170 #  include <errno.h>
    00171 #endif
    00172
    00173 #ifdef HAVE_LOCALE_H
    00174 #  include <locale.h>
    00175 #endif
    00176
    00177 #ifdef _AIX
    00178 #  include <strings.h>
    00179 #endif
    00180
    00181 #if defined(HAVE_LIBDBMALLOC) && defined(HAVE_DBMALLOC_H) && defined(DEBUG)
    00182 #  define DBMALLOC
    00183 #  include <dbmalloc.h>
    00184 #endif
    00185
    00186 #if !defined(DBMALLOC) && defined(HAVE_DMALLOC_H)
    00187 #  define USE_DMALLOC
    00188 #  include <dmalloc.h>
    00189 #endif
    00190
    00191 /* ==================================================================== */
    00192 /*      Base portability stuff ... this stuff may need to be            */
    00193 /*      modified for new platforms.                                     */
    00194 /* ==================================================================== */
    00195
    00196 /*---------------------------------------------------------------------
    00197  *        types for 16 and 32 bits integers, etc...
    00198  *--------------------------------------------------------------------*/
    00199 #if UINT_MAX == 65535
    00200 typedef long            GInt32;
    00201 typedef unsigned long   GUInt32;
    00202 #else
    00203 typedef int             GInt32;
    00204 typedef unsigned int    GUInt32;
    00205 #endif
    00206
    00207 typedef short           GInt16;
    00208 typedef unsigned short  GUInt16;
    00209 typedef unsigned char   GByte;
    00210 typedef int             GBool;
    00211
    00212 /* -------------------------------------------------------------------- */
    00213 /*      64bit support                                                   */
    00214 /* -------------------------------------------------------------------- */
    00215
    00216 #if defined(WIN32) && defined(_MSC_VER)
    00217
    00218 #define VSI_LARGE_API_SUPPORTED
    00219 typedef __int64          GIntBig;
    00220 typedef unsigned __int64 GUIntBig;
    00221
    00222 #elif HAVE_LONG_LONG
    00223
    00224 typedef long long        GIntBig;
    00225 typedef unsigned long long GUIntBig;
    00226
    00227 #else
    00228
    00229 typedef long             GIntBig;
    00230 typedef unsigned long    GUIntBig;
    00231
    00232 #endif
    00233
    00234 /* ==================================================================== */
    00235 /*      Other standard services.                                        */
    00236 /* ==================================================================== */
    00237 #ifdef __cplusplus
    00238 #  define CPL_C_START           extern "C" {
    00239 #  define CPL_C_END             }
    00240 #else
    00241 #  define CPL_C_START
    00242 #  define CPL_C_END
    00243 #endif
    00244
    00245 #ifndef CPL_DLL
    00246 #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
    00247 #  define CPL_DLL     __declspec(dllexport)
    00248 #else
    00249 #  define CPL_DLL
    00250 #endif
    00251 #endif
    00252
    00253 // Should optional (normally private) interfaces be exported?
    00254 #ifdef CPL_OPTIONAL_APIS
    00255 #  define CPL_ODLL CPL_DLL
    00256 #else
    00257 #  define CPL_ODLL
    00258 #endif
    00259
    00260 #ifndef CPL_STDCALL
    00261 #if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL)
    00262 #  define CPL_STDCALL     __stdcall
    00263 #else
    00264 #  define CPL_STDCALL
    00265 #endif
    00266 #endif
    00267
    00268 #ifdef _MSC_VER
    00269 #  define FORCE_CDECL  __cdecl
    00270 #else
    00271 #  define FORCE_CDECL
    00272 #endif
    00273
    00274 #ifndef NULL
    00275 #  define NULL  0
    00276 #endif
    00277
    00278 #ifndef FALSE
    00279 #  define FALSE 0
    00280 #endif
    00281
    00282 #ifndef TRUE
    00283 #  define TRUE  1
    00284 #endif
    00285
    00286 #ifndef MAX
    00287 #  define MIN(a,b)      ((a<b) ? a : b)
    00288 #  define MAX(a,b)      ((a>b) ? a : b)
    00289 #endif
    00290
    00291 #ifndef ABS
    00292 #  define ABS(x)        ((x<0) ? (-1*(x)) : x)
    00293 #endif
    00294
    00295 /* -------------------------------------------------------------------- */
    00296 /*      Macro to test equality of two floating point values.            */
    00297 /*      We use fabs() function instead of ABS() macro to avoid side     */
    00298 /*      effects.                                                        */
    00299 /* -------------------------------------------------------------------- */
    00300 #ifndef CPLIsEqual
    00301 #  define CPLIsEqual(x,y) (fabs(fabs(x) - fabs(y)) < 0.0000000000001 ? 1 : 0)
    00302 #endif
    00303
    00304 #ifndef EQUAL
    00305 #if defined(WIN32) || defined(WIN32CE)
    00306 #  define EQUALN(a,b,n)           (strnicmp(a,b,n)==0)
    00307 #  define EQUAL(a,b)              (stricmp(a,b)==0)
    00308 #else
    00309 #  define EQUALN(a,b,n)           (strncasecmp(a,b,n)==0)
    00310 #  define EQUAL(a,b)              (strcasecmp(a,b)==0)
    00311 #endif
    00312 #endif
    00313
    00314 #ifdef macos_pre10
    00315 int strcasecmp(char * str1, char * str2);
    00316 int strncasecmp(char * str1, char * str2, int len);
    00317 char * strdup (char *instr);
    00318 #endif
    00319
    00320 #ifndef CPL_THREADLOCAL
    00321 #  define CPL_THREADLOCAL
    00322 #endif
    00323
    00324 /* -------------------------------------------------------------------- */
    00325 /*      Handle isnan() and isinf().  Note that isinf() and isnan()      */
    00326 /*      are supposed to be macros according to C99.  Some systems       */
    00327 /*      (ie. Tru64) don't have isinf() at all, so if the macro is       */
    00328 /*      not defined we just assume nothing is infinite.  This may       */
    00329 /*      mean we have no real CPLIsInf() on systems with an isinf()      */
    00330 /*      function but no corresponding macro, but I can live with        */
    00331 /*      that since it isn't that important a test.                      */
    00332 /* -------------------------------------------------------------------- */
    00333 #ifdef _MSC_VER
    00334 #  define CPLIsNan(x) _isnan(x)
    00335 #  define CPLIsInf(x) (!_isnan(x) && !_finite(x))
    00336 #  define CPLIsFinite(x) _finite(x)
    00337 #else
    00338 #  define CPLIsNan(x) isnan(x)
    00339 #  ifdef isinf
    00340 #    define CPLIsInf(x) isinf(x)
    00341 #    define CPLIsFinite(x) (!isnan(x) && !isinf(x))
    00342 #  else
    00343 #    define CPLIsInf(x)    FALSE
    00344 #    define CPLIsFinite(x) (!isnan(x))
    00345 #  endif
    00346 #endif
    00347
    00348 /*---------------------------------------------------------------------
    00349  *                         CPL_LSB and CPL_MSB
    00350  * Only one of these 2 macros should be defined and specifies the byte
    00351  * ordering for the current platform.
    00352  * This should be defined in the Makefile, but if it is not then
    00353  * the default is CPL_LSB (Intel ordering, LSB first).
    00354  *--------------------------------------------------------------------*/
    00355 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
    00356 #  define CPL_MSB
    00357 #endif
    00358
    00359 #if ! ( defined(CPL_LSB) || defined(CPL_MSB) )
    00360 #define CPL_LSB
    00361 #endif
    00362
    00363 #if defined(CPL_LSB)
    00364 #  define CPL_IS_LSB 1
    00365 #else
    00366 #  define CPL_IS_LSB 0
    00367 #endif
    00368
    00369 /*---------------------------------------------------------------------
    00370  *        Little endian <==> big endian byte swap macros.
    00371  *--------------------------------------------------------------------*/
    00372
    00373 #define CPL_SWAP16(x) \
    00374         ((GUInt16)( \
    00375             (((GUInt16)(x) & 0x00ffU) << 8) | \
    00376             (((GUInt16)(x) & 0xff00U) >> 8) ))
    00377
    00378 #define CPL_SWAP16PTR(x) \
    00379 {                                                                 \
    00380     GByte       byTemp, *_pabyDataT = (GByte *) (x);              \
    00381                                                                   \
    00382     byTemp = _pabyDataT[0];                                       \
    00383     _pabyDataT[0] = _pabyDataT[1];                                \
    00384     _pabyDataT[1] = byTemp;                                       \
    00385 }
    00386
    00387 #define CPL_SWAP32(x) \
    00388         ((GUInt32)( \
    00389             (((GUInt32)(x) & (GUInt32)0x000000ffUL) << 24) | \
    00390             (((GUInt32)(x) & (GUInt32)0x0000ff00UL) <<  8) | \
    00391             (((GUInt32)(x) & (GUInt32)0x00ff0000UL) >>  8) | \
    00392             (((GUInt32)(x) & (GUInt32)0xff000000UL) >> 24) ))
    00393
    00394 #define CPL_SWAP32PTR(x) \
    00395 {                                                                 \
    00396     GByte       byTemp, *_pabyDataT = (GByte *) (x);              \
    00397                                                                   \
    00398     byTemp = _pabyDataT[0];                                       \
    00399     _pabyDataT[0] = _pabyDataT[3];                                \
    00400     _pabyDataT[3] = byTemp;                                       \
    00401     byTemp = _pabyDataT[1];                                       \
    00402     _pabyDataT[1] = _pabyDataT[2];                                \
    00403     _pabyDataT[2] = byTemp;                                       \
    00404 }
    00405
    00406 #define CPL_SWAP64PTR(x) \
    00407 {                                                                 \
    00408     GByte       byTemp, *_pabyDataT = (GByte *) (x);              \
    00409                                                                   \
    00410     byTemp = _pabyDataT[0];                                       \
    00411     _pabyDataT[0] = _pabyDataT[7];                                \
    00412     _pabyDataT[7] = byTemp;                                       \
    00413     byTemp = _pabyDataT[1];                                       \
    00414     _pabyDataT[1] = _pabyDataT[6];                                \
    00415     _pabyDataT[6] = byTemp;                                       \
    00416     byTemp = _pabyDataT[2];                                       \
    00417     _pabyDataT[2] = _pabyDataT[5];                                \
    00418     _pabyDataT[5] = byTemp;                                       \
    00419     byTemp = _pabyDataT[3];                                       \
    00420     _pabyDataT[3] = _pabyDataT[4];                                \
    00421     _pabyDataT[4] = byTemp;                                       \
    00422 }
    00423
    00424
    00425 /* Until we have a safe 64 bits integer data type defined, we'll replace
    00426 m * this version of the CPL_SWAP64() macro with a less efficient one.
    00427  */
    00428 /*
    00429 #define CPL_SWAP64(x) \
    00430         ((uint64)( \
    00431             (uint64)(((uint64)(x) & (uint64)0x00000000000000ffULL) << 56) | \
    00432             (uint64)(((uint64)(x) & (uint64)0x000000000000ff00ULL) << 40) | \
    00433             (uint64)(((uint64)(x) & (uint64)0x0000000000ff0000ULL) << 24) | \
    00434             (uint64)(((uint64)(x) & (uint64)0x00000000ff000000ULL) << 8) | \
    00435             (uint64)(((uint64)(x) & (uint64)0x000000ff00000000ULL) >> 8) | \
    00436             (uint64)(((uint64)(x) & (uint64)0x0000ff0000000000ULL) >> 24) | \
    00437             (uint64)(((uint64)(x) & (uint64)0x00ff000000000000ULL) >> 40) | \
    00438             (uint64)(((uint64)(x) & (uint64)0xff00000000000000ULL) >> 56) ))
    00439 */
    00440
    00441 #define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
    00442
    00443 #ifdef CPL_MSB
    00444 #  define CPL_MSBWORD16(x)      (x)
    00445 #  define CPL_LSBWORD16(x)      CPL_SWAP16(x)
    00446 #  define CPL_MSBWORD32(x)      (x)
    00447 #  define CPL_LSBWORD32(x)      CPL_SWAP32(x)
    00448 #  define CPL_MSBPTR16(x)
    00449 #  define CPL_LSBPTR16(x)       CPL_SWAP16PTR(x)
    00450 #  define CPL_MSBPTR32(x)
    00451 #  define CPL_LSBPTR32(x)       CPL_SWAP32PTR(x)
    00452 #  define CPL_MSBPTR64(x)
    00453 #  define CPL_LSBPTR64(x)       CPL_SWAP64PTR(x)
    00454 #else
    00455 #  define CPL_LSBWORD16(x)      (x)
    00456 #  define CPL_MSBWORD16(x)      CPL_SWAP16(x)
    00457 #  define CPL_LSBWORD32(x)      (x)
    00458 #  define CPL_MSBWORD32(x)      CPL_SWAP32(x)
    00459 #  define CPL_LSBPTR16(x)
    00460 #  define CPL_MSBPTR16(x)       CPL_SWAP16PTR(x)
    00461 #  define CPL_LSBPTR32(x)
    00462 #  define CPL_MSBPTR32(x)       CPL_SWAP32PTR(x)
    00463 #  define CPL_LSBPTR64(x)
    00464 #  define CPL_MSBPTR64(x)       CPL_SWAP64PTR(x)
    00465 #endif
    00466
    00467 /***********************************************************************
    00468  * Define CPL_CVSID() macro.  It can be disabled during a build by
    00469  * defining DISABLE_CPLID in the compiler options.
    00470  *
    00471  * The cvsid_aw() function is just there to prevent reports of cpl_cvsid()
    00472  * being unused.
    00473  */
    00474
    00475 #ifndef DISABLE_CVSID
    00476 #  define CPL_CVSID(string)     static char cpl_cvsid[] = string; \
    00477 static char *cvsid_aw() { return( cvsid_aw() ? ((char *) NULL) : cpl_cvsid ); }
    00478 #else
    00479 #  define CPL_CVSID(string)
    00480 #endif
    00481
    00482 #endif /* ndef CPL_BASE_H_INCLUDED */

Generated for GDAL by 1.4.5.