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.8 2001/07/05 13:24:08 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.8  2001/07/05 13:24:08  warmerda
00044  * *** empty log message ***
00044  *
00045  * Revision 1.26  2001/06/21 21:17:26  warmerda
00046  * added irix 64bit file api support
00047  *
00048  * Revision 1.25  2001/04/30 18:18:38  warmerda
00049  * added macos support, standard header
00050  *
00051  * Revision 1.24  2001/01/19 21:16:41  warmerda
00052  * expanded tabs
00053  *
00054  * Revision 1.23  2001/01/13 04:06:39  warmerda
00055  * added strings.h on AIX as per patch from Dale.
00056  *
00057  * Revision 1.22  2001/01/03 16:18:07  warmerda
00058  * added GUIntBig
00059  *
00060  * Revision 1.21  2000/10/20 04:20:33  warmerda
00061  * added SWAP16PTR macros
00062  *
00063  * Revision 1.20  2000/10/13 17:32:42  warmerda
00064  * check for unix instead of IGNORE_WIN32
00065  *
00066  * Revision 1.19  2000/09/25 19:58:43  warmerda
00067  * ensure win32 doesn't get defined in Cygnus builds
00068  *
00069  * Revision 1.18  2000/07/20 13:15:03  warmerda
00070  * don't redeclare CPL_DLL
00071  */
00072 
00073 #ifndef CPL_BASE_H_INCLUDED
00074 #define CPL_BASE_H_INCLUDED
00075 
00083 /* ==================================================================== */
00084 /*      We will use macos_pre10 to indicate compilation with MacOS      */
00085 /*      versions before MacOS X.                                        */
00086 /* ==================================================================== */
00087 #ifdef macintosh
00088 #  define macos_pre10
00089 #endif
00090 
00091 /* ==================================================================== */
00092 /*      We will use WIN32 as a standard windows define.                 */
00093 /* ==================================================================== */
00094 #if defined(_WIN32) && !defined(WIN32)
00095 #  define WIN32
00096 #endif
00097 
00098 #if defined(_WINDOWS) && !defined(WIN32)
00099 #  define WIN32
00100 #endif
00101 
00102 #include "cpl_config.h"
00103 
00104 /* ==================================================================== */
00105 /*      This will disable most WIN32 stuff in a Cygnus build which      */
00106 /*      defines unix to 1.                                              */
00107 /* ==================================================================== */
00108 
00109 #ifdef unix
00110 #  undef WIN32
00111 #endif
00112 
00113 /* ==================================================================== */
00114 /*      Standard include files.                                         */
00115 /* ==================================================================== */
00116 
00117 #include <stdio.h>
00118 #include <stdlib.h>
00119 #include <math.h>
00120 #include <stdarg.h>
00121 #include <string.h>
00122 #include <errno.h>
00123 
00124 #ifdef _AIX
00125 #  include <strings.h>
00126 #endif
00127 
00128 #if defined(HAVE_LIBDBMALLOC) && defined(HAVE_DBMALLOC_H) && defined(DEBUG)
00129 #  define DBMALLOC
00130 #  include <dbmalloc.h>
00131 #endif
00132 
00133 #if !defined(DBMALLOC) && defined(HAVE_DMALLOC_H)
00134 #  define USE_DMALLOC
00135 #  include <dmalloc.h>
00136 #endif
00137 
00138 /* ==================================================================== */
00139 /*      Base portability stuff ... this stuff may need to be            */
00140 /*      modified for new platforms.                                     */
00141 /* ==================================================================== */
00142 
00143 /*---------------------------------------------------------------------
00144  *        types for 16 and 32 bits integers, etc...
00145  *--------------------------------------------------------------------*/
00146 #if UINT_MAX == 65535
00147 typedef long            GInt32;
00148 typedef unsigned long   GUInt32;
00149 #else
00150 typedef int             GInt32;
00151 typedef unsigned int    GUInt32;
00152 #endif
00153 
00154 typedef short           GInt16;
00155 typedef unsigned short  GUInt16;
00156 typedef unsigned char   GByte;
00157 typedef int             GBool;
00158 
00159 /* -------------------------------------------------------------------- */
00160 /*      64bit support                                                   */
00161 /* -------------------------------------------------------------------- */
00162 
00163 #ifdef WIN32
00164 
00165 #define VSI_LARGE_API_SUPPORTED
00166 typedef __int64          GIntBig;
00167 typedef unsigned __int64 GUIntBig;
00168 
00169 #elif HAVE_LONG_LONG
00170 
00171 typedef long long        GIntBig;
00172 typedef unsigned long long GUIntBig;
00173 
00174 #else
00175 
00176 typedef long             GIntBig;
00177 typedef unsigned long    GUIntBig;
00178 
00179 #endif
00180 
00181 /* ==================================================================== */
00182 /*      Other standard services.                                        */
00183 /* ==================================================================== */
00184 #ifdef __cplusplus
00185 #  define CPL_C_START           extern "C" {
00186 #  define CPL_C_END             }
00187 #else
00188 #  define CPL_C_START
00189 #  define CPL_C_END
00190 #endif
00191 
00192 #ifndef CPL_DLL
00193 #if defined(WIN32) && !defined(CPL_DISABLE_DLL)
00194 #  define CPL_DLL     __declspec(dllexport)
00195 #else
00196 #  define CPL_DLL
00197 #endif
00198 #endif
00199 
00200 
00201 #ifndef NULL
00202 #  define NULL  0
00203 #endif
00204 
00205 #ifndef FALSE
00206 #  define FALSE 0
00207 #endif
00208 
00209 #ifndef TRUE
00210 #  define TRUE  1
00211 #endif
00212 
00213 #ifndef MAX
00214 #  define MIN(a,b)      ((a<b) ? a : b)
00215 #  define MAX(a,b)      ((a>b) ? a : b)
00216 #endif
00217 
00218 #ifndef ABS
00219 #  define ABS(x)        ((x<0) ? (-1*(x)) : x)
00220 #endif
00221 
00222 #ifndef EQUAL
00223 #ifdef WIN32
00224 #  define EQUALN(a,b,n)           (strnicmp(a,b,n)==0)
00225 #  define EQUAL(a,b)              (stricmp(a,b)==0)
00226 #else
00227 #  define EQUALN(a,b,n)           (strncasecmp(a,b,n)==0)
00228 #  define EQUAL(a,b)              (strcasecmp(a,b)==0)
00229 #endif
00230 #endif
00231 
00232 #ifdef macos_pre10
00233 int strcasecmp(char * str1, char * str2);
00234 int strncasecmp(char * str1, char * str2, int len);
00235 char * strdup (char *instr);
00236 #endif
00237 
00238 /*---------------------------------------------------------------------
00239  *                         CPL_LSB and CPL_MSB
00240  * Only one of these 2 macros should be defined and specifies the byte 
00241  * ordering for the current platform.  
00242  * This should be defined in the Makefile, but if it is not then
00243  * the default is CPL_LSB (Intel ordering, LSB first).
00244  *--------------------------------------------------------------------*/
00245 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
00246 #  define CPL_MSB
00247 #endif
00248 
00249 #if ! ( defined(CPL_LSB) || defined(CPL_MSB) )
00250 #define CPL_LSB
00251 #endif
00252 
00253 /*---------------------------------------------------------------------
00254  *        Little endian <==> big endian byte swap macros.
00255  *--------------------------------------------------------------------*/
00256 
00257 #define CPL_SWAP16(x) \
00258         ((GUInt16)( \
00259             (((GUInt16)(x) & 0x00ffU) << 8) | \
00260             (((GUInt16)(x) & 0xff00U) >> 8) ))
00261 
00262 #define CPL_SWAP16PTR(x) \
00263 {                                                               \
00264     GByte       byTemp, *pabyData = (GByte *) (x);              \
00265                                                                 \
00266     byTemp = pabyData[0];                                       \
00267     pabyData[0] = pabyData[1];                                  \
00268     pabyData[1] = byTemp;                                       \
00269 }                                                                    
00270                                                             
00271 #define CPL_SWAP32(x) \
00272         ((GUInt32)( \
00273             (((GUInt32)(x) & (GUInt32)0x000000ffUL) << 24) | \
00274             (((GUInt32)(x) & (GUInt32)0x0000ff00UL) <<  8) | \
00275             (((GUInt32)(x) & (GUInt32)0x00ff0000UL) >>  8) | \
00276             (((GUInt32)(x) & (GUInt32)0xff000000UL) >> 24) ))
00277 
00278 #define CPL_SWAP32PTR(x) \
00279 {                                                               \
00280     GByte       byTemp, *pabyData = (GByte *) (x);              \
00281                                                                 \
00282     byTemp = pabyData[0];                                       \
00283     pabyData[0] = pabyData[3];                                  \
00284     pabyData[3] = byTemp;                                       \
00285     byTemp = pabyData[1];                                       \
00286     pabyData[1] = pabyData[2];                                  \
00287     pabyData[2] = byTemp;                                       \
00288 }                                                                    
00289                                                             
00290 #define CPL_SWAP64PTR(x) \
00291 {                                                               \
00292     GByte       byTemp, *pabyData = (GByte *) (x);              \
00293                                                                 \
00294     byTemp = pabyData[0];                                       \
00295     pabyData[0] = pabyData[7];                                  \
00296     pabyData[7] = byTemp;                                       \
00297     byTemp = pabyData[1];                                       \
00298     pabyData[1] = pabyData[6];                                  \
00299     pabyData[6] = byTemp;                                       \
00300     byTemp = pabyData[2];                                       \
00301     pabyData[2] = pabyData[5];                                  \
00302     pabyData[5] = byTemp;                                       \
00303     byTemp = pabyData[3];                                       \
00304     pabyData[3] = pabyData[4];                                  \
00305     pabyData[4] = byTemp;                                       \
00306 }                                                                    
00307                                                             
00308 
00309 /* Until we have a safe 64 bits integer data type defined, we'll replace
00310 m * this version of the CPL_SWAP64() macro with a less efficient one.
00311  */
00312 /*
00313 #define CPL_SWAP64(x) \
00314         ((uint64)( \
00315             (uint64)(((uint64)(x) & (uint64)0x00000000000000ffULL) << 56) | \
00316             (uint64)(((uint64)(x) & (uint64)0x000000000000ff00ULL) << 40) | \
00317             (uint64)(((uint64)(x) & (uint64)0x0000000000ff0000ULL) << 24) | \
00318             (uint64)(((uint64)(x) & (uint64)0x00000000ff000000ULL) << 8) | \
00319             (uint64)(((uint64)(x) & (uint64)0x000000ff00000000ULL) >> 8) | \
00320             (uint64)(((uint64)(x) & (uint64)0x0000ff0000000000ULL) >> 24) | \
00321             (uint64)(((uint64)(x) & (uint64)0x00ff000000000000ULL) >> 40) | \
00322             (uint64)(((uint64)(x) & (uint64)0xff00000000000000ULL) >> 56) ))
00323 */
00324 
00325 #define CPL_SWAPDOUBLE(p) {                             \
00326         double _tmp = *(double *)(p);                     \
00327         ((GByte *)(p))[0] = ((GByte *)&_tmp)[7];          \
00328         ((GByte *)(p))[1] = ((GByte *)&_tmp)[6];          \
00329         ((GByte *)(p))[2] = ((GByte *)&_tmp)[5];          \
00330         ((GByte *)(p))[3] = ((GByte *)&_tmp)[4];          \
00331         ((GByte *)(p))[4] = ((GByte *)&_tmp)[3];          \
00332         ((GByte *)(p))[5] = ((GByte *)&_tmp)[2];          \
00333         ((GByte *)(p))[6] = ((GByte *)&_tmp)[1];          \
00334         ((GByte *)(p))[7] = ((GByte *)&_tmp)[0];          \
00335 }
00336 
00337 #ifdef CPL_MSB
00338 #  define CPL_MSBWORD16(x)      (x)
00339 #  define CPL_LSBWORD16(x)      CPL_SWAP16(x)
00340 #  define CPL_MSBWORD32(x)      (x)
00341 #  define CPL_LSBWORD32(x)      CPL_SWAP32(x)
00342 #  define CPL_MSBPTR16(x)       
00343 #  define CPL_LSBPTR16(x)       CPL_SWAP16PTR(x)
00344 #  define CPL_MSBPTR32(x)       
00345 #  define CPL_LSBPTR32(x)       CPL_SWAP32PTR(x)
00346 #  define CPL_MSBPTR64(x)       
00347 #  define CPL_LSBPTR64(x)       CPL_SWAP64PTR(x)
00348 #else
00349 #  define CPL_LSBWORD16(x)      (x)
00350 #  define CPL_MSBWORD16(x)      CPL_SWAP16(x)
00351 #  define CPL_LSBWORD32(x)      (x)
00352 #  define CPL_MSBWORD32(x)      CPL_SWAP32(x)
00353 #  define CPL_LSBPTR16(x)       
00354 #  define CPL_MSBPTR16(x)       CPL_SWAP16PTR(x)
00355 #  define CPL_LSBPTR32(x)       
00356 #  define CPL_MSBPTR32(x)       CPL_SWAP32PTR(x)
00357 #  define CPL_LSBPTR64(x)       
00358 #  define CPL_MSBPTR64(x)       CPL_SWAP64PTR(x)
00359 #endif
00360 
00361 #endif /* ndef CPL_BASE_H_INCLUDED */

Generated at Thu Jul 5 09:16:11 2001 for GDAL by doxygen1.2.3-20001105 written by Dimitri van Heesch, © 1997-2000