Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

cpl_port.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: cpl_port_h-source.html,v 1.10 2002/04/16 13:11:47 warmerda Exp $
00003  *
00004  * Project:  CPL - Common Portability Library
00005  * Author:   Frank Warmerdam, warmerdam@pobox.com
00006  * Purpose:  
00007  * Include file providing low level portability services for CPL.  This
00008  * should be the first include file for any CPL based code.  It provides the
00009  * following:
00010  *
00011  * o Includes some standard system include files, such as stdio, and stdlib.
00012  *
00013  * o Defines CPL_C_START, CPL_C_END macros.
00014  *
00015  * o Ensures that some other standard macros like NULL are defined.
00016  *
00017  * o Defines some portability stuff like CPL_MSB, or CPL_LSB.
00018  *
00019  * o Ensures that core types such as GBool, GInt32, GInt16, GUInt32, 
00020  *   GUInt16, and GByte are defined.
00021  *
00022  ******************************************************************************
00023  * Copyright (c) 1998, Frank Warmerdam
00024  *
00025  * Permission is hereby granted, free of charge, to any person obtaining a
00026  * copy of this software and associated documentation files (the "Software"),
00027  * to deal in the Software without restriction, including without limitation
00028  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00029  * and/or sell copies of the Software, and to permit persons to whom the
00030  * Software is furnished to do so, subject to the following conditions:
00031  *
00032  * The above copyright notice and this permission notice shall be included
00033  * in all copies or substantial portions of the Software.
00034  *
00035  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00036  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00037  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00038  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00039  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00040  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00041  * DEALINGS IN THE SOFTWARE.
00042  ******************************************************************************
00043  *
00044  * $Log: cpl_port_h-source.html,v $
00044  * Revision 1.10  2002/04/16 13:11:47  warmerda
00044  * updated
00044  *
00045  * Revision 1.29  2002/01/17 01:40:27  warmerda
00046  * added _LARGEFILE64_SOURCE support
00047  *
00048  * Revision 1.28  2001/08/30 21:20:49  warmerda
00049  * expand tabs
00050  *
00051  * Revision 1.27  2001/07/18 04:00:49  warmerda
00052  * added CPL_CVSID
00053  *
00054  * Revision 1.26  2001/06/21 21:17:26  warmerda
00055  * added irix 64bit file api support
00056  *
00057  * Revision 1.25  2001/04/30 18:18:38  warmerda
00058  * added macos support, standard header
00059  *
00060  * Revision 1.24  2001/01/19 21:16:41  warmerda
00061  * expanded tabs
00062  *
00063  * Revision 1.23  2001/01/13 04:06:39  warmerda
00064  * added strings.h on AIX as per patch from Dale.
00065  *
00066  * Revision 1.22  2001/01/03 16:18:07  warmerda
00067  * added GUIntBig
00068  *
00069  * Revision 1.21  2000/10/20 04:20:33  warmerda
00070  * added SWAP16PTR macros
00071  *
00072  * Revision 1.20  2000/10/13 17:32:42  warmerda
00073  * check for unix instead of IGNORE_WIN32
00074  *
00075  * Revision 1.19  2000/09/25 19:58:43  warmerda
00076  * ensure win32 doesn't get defined in Cygnus builds
00077  *
00078  * Revision 1.18  2000/07/20 13:15:03  warmerda
00079  * don't redeclare CPL_DLL
00080  */
00081 
00082 #ifndef CPL_BASE_H_INCLUDED
00083 #define CPL_BASE_H_INCLUDED
00084 
00092 /* ==================================================================== */
00093 /*      We will use macos_pre10 to indicate compilation with MacOS      */
00094 /*      versions before MacOS X.                                        */
00095 /* ==================================================================== */
00096 #ifdef macintosh
00097 #  define macos_pre10
00098 #endif
00099 
00100 /* ==================================================================== */
00101 /*      We will use WIN32 as a standard windows define.                 */
00102 /* ==================================================================== */
00103 #if defined(_WIN32) && !defined(WIN32)
00104 #  define WIN32
00105 #endif
00106 
00107 #if defined(_WINDOWS) && !defined(WIN32)
00108 #  define WIN32
00109 #endif
00110 
00111 #include "cpl_config.h"
00112 
00113 /* ==================================================================== */
00114 /*      This will disable most WIN32 stuff in a Cygnus build which      */
00115 /*      defines unix to 1.                                              */
00116 /* ==================================================================== */
00117 
00118 #ifdef unix
00119 #  undef WIN32
00120 #endif
00121 
00122 #if defined(VSI_NEED_LARGEFILE64_SOURCE) && !defined(_LARGEFILE64_SOURCE)
00123 #  define _LARGEFILE64_SOURCE 1
00124 #endif
00125 
00126 /* ==================================================================== */
00127 /*      Standard include files.                                         */
00128 /* ==================================================================== */
00129 
00130 #include <stdio.h>
00131 #include <stdlib.h>
00132 #include <math.h>
00133 #include <stdarg.h>
00134 #include <string.h>
00135 #include <errno.h>
00136 
00137 #ifdef _AIX
00138 #  include <strings.h>
00139 #endif
00140 
00141 #if defined(HAVE_LIBDBMALLOC) && defined(HAVE_DBMALLOC_H) && defined(DEBUG)
00142 #  define DBMALLOC
00143 #  include <dbmalloc.h>
00144 #endif
00145 
00146 #if !defined(DBMALLOC) && defined(HAVE_DMALLOC_H)
00147 #  define USE_DMALLOC
00148 #  include <dmalloc.h>
00149 #endif
00150 
00151 /* ==================================================================== */
00152 /*      Base portability stuff ... this stuff may need to be            */
00153 /*      modified for new platforms.                                     */
00154 /* ==================================================================== */
00155 
00156 /*---------------------------------------------------------------------
00157  *        types for 16 and 32 bits integers, etc...
00158  *--------------------------------------------------------------------*/
00159 #if UINT_MAX == 65535
00160 typedef long            GInt32;
00161 typedef unsigned long   GUInt32;
00162 #else
00163 typedef int             GInt32;
00164 typedef unsigned int    GUInt32;
00165 #endif
00166 
00167 typedef short           GInt16;
00168 typedef unsigned short  GUInt16;
00169 typedef unsigned char   GByte;
00170 typedef int             GBool;
00171 
00172 /* -------------------------------------------------------------------- */
00173 /*      64bit support                                                   */
00174 /* -------------------------------------------------------------------- */
00175 
00176 #ifdef WIN32
00177 
00178 #define VSI_LARGE_API_SUPPORTED
00179 typedef __int64          GIntBig;
00180 typedef unsigned __int64 GUIntBig;
00181 
00182 #elif HAVE_LONG_LONG
00183 
00184 typedef long long        GIntBig;
00185 typedef unsigned long long GUIntBig;
00186 
00187 #else
00188 
00189 typedef long             GIntBig;
00190 typedef unsigned long    GUIntBig;
00191 
00192 #endif
00193 
00194 /* ==================================================================== */
00195 /*      Other standard services.                                        */
00196 /* ==================================================================== */
00197 #ifdef __cplusplus
00198 #  define CPL_C_START           extern "C" {
00199 #  define CPL_C_END             }
00200 #else
00201 #  define CPL_C_START
00202 #  define CPL_C_END
00203 #endif
00204 
00205 #ifndef CPL_DLL
00206 #if defined(WIN32) && !defined(CPL_DISABLE_DLL)
00207 #  define CPL_DLL     __declspec(dllexport)
00208 #else
00209 #  define CPL_DLL
00210 #endif
00211 #endif
00212 
00213 
00214 #ifndef NULL
00215 #  define NULL  0
00216 #endif
00217 
00218 #ifndef FALSE
00219 #  define FALSE 0
00220 #endif
00221 
00222 #ifndef TRUE
00223 #  define TRUE  1
00224 #endif
00225 
00226 #ifndef MAX
00227 #  define MIN(a,b)      ((a<b) ? a : b)
00228 #  define MAX(a,b)      ((a>b) ? a : b)
00229 #endif
00230 
00231 #ifndef ABS
00232 #  define ABS(x)        ((x<0) ? (-1*(x)) : x)
00233 #endif
00234 
00235 #ifndef EQUAL
00236 #ifdef WIN32
00237 #  define EQUALN(a,b,n)           (strnicmp(a,b,n)==0)
00238 #  define EQUAL(a,b)              (stricmp(a,b)==0)
00239 #else
00240 #  define EQUALN(a,b,n)           (strncasecmp(a,b,n)==0)
00241 #  define EQUAL(a,b)              (strcasecmp(a,b)==0)
00242 #endif
00243 #endif
00244 
00245 #ifdef macos_pre10
00246 int strcasecmp(char * str1, char * str2);
00247 int strncasecmp(char * str1, char * str2, int len);
00248 char * strdup (char *instr);
00249 #endif
00250 
00251 /*---------------------------------------------------------------------
00252  *                         CPL_LSB and CPL_MSB
00253  * Only one of these 2 macros should be defined and specifies the byte 
00254  * ordering for the current platform.  
00255  * This should be defined in the Makefile, but if it is not then
00256  * the default is CPL_LSB (Intel ordering, LSB first).
00257  *--------------------------------------------------------------------*/
00258 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
00259 #  define CPL_MSB
00260 #endif
00261 
00262 #if ! ( defined(CPL_LSB) || defined(CPL_MSB) )
00263 #define CPL_LSB
00264 #endif
00265 
00266 /*---------------------------------------------------------------------
00267  *        Little endian <==> big endian byte swap macros.
00268  *--------------------------------------------------------------------*/
00269 
00270 #define CPL_SWAP16(x) \
00271         ((GUInt16)( \
00272             (((GUInt16)(x) & 0x00ffU) << 8) | \
00273             (((GUInt16)(x) & 0xff00U) >> 8) ))
00274 
00275 #define CPL_SWAP16PTR(x) \
00276 {                                                               \
00277     GByte       byTemp, *pabyData = (GByte *) (x);              \
00278                                                                 \
00279     byTemp = pabyData[0];                                       \
00280     pabyData[0] = pabyData[1];                                  \
00281     pabyData[1] = byTemp;                                       \
00282 }                                                                    
00283                                                             
00284 #define CPL_SWAP32(x) \
00285         ((GUInt32)( \
00286             (((GUInt32)(x) & (GUInt32)0x000000ffUL) << 24) | \
00287             (((GUInt32)(x) & (GUInt32)0x0000ff00UL) <<  8) | \
00288             (((GUInt32)(x) & (GUInt32)0x00ff0000UL) >>  8) | \
00289             (((GUInt32)(x) & (GUInt32)0xff000000UL) >> 24) ))
00290 
00291 #define CPL_SWAP32PTR(x) \
00292 {                                                               \
00293     GByte       byTemp, *pabyData = (GByte *) (x);              \
00294                                                                 \
00295     byTemp = pabyData[0];                                       \
00296     pabyData[0] = pabyData[3];                                  \
00297     pabyData[3] = byTemp;                                       \
00298     byTemp = pabyData[1];                                       \
00299     pabyData[1] = pabyData[2];                                  \
00300     pabyData[2] = byTemp;                                       \
00301 }                                                                    
00302                                                             
00303 #define CPL_SWAP64PTR(x) \
00304 {                                                               \
00305     GByte       byTemp, *pabyData = (GByte *) (x);              \
00306                                                                 \
00307     byTemp = pabyData[0];                                       \
00308     pabyData[0] = pabyData[7];                                  \
00309     pabyData[7] = byTemp;                                       \
00310     byTemp = pabyData[1];                                       \
00311     pabyData[1] = pabyData[6];                                  \
00312     pabyData[6] = byTemp;                                       \
00313     byTemp = pabyData[2];                                       \
00314     pabyData[2] = pabyData[5];                                  \
00315     pabyData[5] = byTemp;                                       \
00316     byTemp = pabyData[3];                                       \
00317     pabyData[3] = pabyData[4];                                  \
00318     pabyData[4] = byTemp;                                       \
00319 }                                                                    
00320                                                             
00321 
00322 /* Until we have a safe 64 bits integer data type defined, we'll replace
00323 m * this version of the CPL_SWAP64() macro with a less efficient one.
00324  */
00325 /*
00326 #define CPL_SWAP64(x) \
00327         ((uint64)( \
00328             (uint64)(((uint64)(x) & (uint64)0x00000000000000ffULL) << 56) | \
00329             (uint64)(((uint64)(x) & (uint64)0x000000000000ff00ULL) << 40) | \
00330             (uint64)(((uint64)(x) & (uint64)0x0000000000ff0000ULL) << 24) | \
00331             (uint64)(((uint64)(x) & (uint64)0x00000000ff000000ULL) << 8) | \
00332             (uint64)(((uint64)(x) & (uint64)0x000000ff00000000ULL) >> 8) | \
00333             (uint64)(((uint64)(x) & (uint64)0x0000ff0000000000ULL) >> 24) | \
00334             (uint64)(((uint64)(x) & (uint64)0x00ff000000000000ULL) >> 40) | \
00335             (uint64)(((uint64)(x) & (uint64)0xff00000000000000ULL) >> 56) ))
00336 */
00337 
00338 #define CPL_SWAPDOUBLE(p) {                             \
00339         double _tmp = *(double *)(p);                     \
00340         ((GByte *)(p))[0] = ((GByte *)&_tmp)[7];          \
00341         ((GByte *)(p))[1] = ((GByte *)&_tmp)[6];          \
00342         ((GByte *)(p))[2] = ((GByte *)&_tmp)[5];          \
00343         ((GByte *)(p))[3] = ((GByte *)&_tmp)[4];          \
00344         ((GByte *)(p))[4] = ((GByte *)&_tmp)[3];          \
00345         ((GByte *)(p))[5] = ((GByte *)&_tmp)[2];          \
00346         ((GByte *)(p))[6] = ((GByte *)&_tmp)[1];          \
00347         ((GByte *)(p))[7] = ((GByte *)&_tmp)[0];          \
00348 }
00349 
00350 #ifdef CPL_MSB
00351 #  define CPL_MSBWORD16(x)      (x)
00352 #  define CPL_LSBWORD16(x)      CPL_SWAP16(x)
00353 #  define CPL_MSBWORD32(x)      (x)
00354 #  define CPL_LSBWORD32(x)      CPL_SWAP32(x)
00355 #  define CPL_MSBPTR16(x)       
00356 #  define CPL_LSBPTR16(x)       CPL_SWAP16PTR(x)
00357 #  define CPL_MSBPTR32(x)       
00358 #  define CPL_LSBPTR32(x)       CPL_SWAP32PTR(x)
00359 #  define CPL_MSBPTR64(x)       
00360 #  define CPL_LSBPTR64(x)       CPL_SWAP64PTR(x)
00361 #else
00362 #  define CPL_LSBWORD16(x)      (x)
00363 #  define CPL_MSBWORD16(x)      CPL_SWAP16(x)
00364 #  define CPL_LSBWORD32(x)      (x)
00365 #  define CPL_MSBWORD32(x)      CPL_SWAP32(x)
00366 #  define CPL_LSBPTR16(x)       
00367 #  define CPL_MSBPTR16(x)       CPL_SWAP16PTR(x)
00368 #  define CPL_LSBPTR32(x)       
00369 #  define CPL_MSBPTR32(x)       CPL_SWAP32PTR(x)
00370 #  define CPL_LSBPTR64(x)       
00371 #  define CPL_MSBPTR64(x)       CPL_SWAP64PTR(x)
00372 #endif
00373 
00374 /***********************************************************************
00375  * Define CPL_CVSID() macro.  It can be disabled during a build by
00376  * defining DISABLE_CPLID in the compiler options.
00377  *
00378  * The cvsid_aw() function is just there to prevent reports of cpl_cvsid()
00379  * being unused.
00380  */
00381 
00382 #ifndef DISABLE_CVSID
00383 #  define CPL_CVSID(string)     static char cpl_cvsid[] = string; \
00384 static char *cvsid_aw() { return( cvsid_aw() ? ((char *) NULL) : cpl_cvsid ); }
00385 #else
00386 #  define CPL_CVSID(string)
00387 #endif
00388 
00389 #endif /* ndef CPL_BASE_H_INCLUDED */

Generated at Thu Mar 28 09:47:28 2002 for GDAL by doxygen1.2.3-20001105 written by Dimitri van Heesch, © 1997-2000