~ubuntu-branches/ubuntu/karmic/e00compr/karmic

« back to all changes in this revision

Viewing changes to cpl_port.h

  • Committer: Bazaar Package Importer
  • Author(s): Paul Wise
  • Date: 2005-11-15 15:43:39 UTC
  • Revision ID: james.westby@ubuntu.com-20051115154339-tmt82iiu3dwtk94a
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 * Copyright (c) 1998, Frank Warmerdam
 
3
 *
 
4
 * Permission is hereby granted, free of charge, to any person obtaining a
 
5
 * copy of this software and associated documentation files (the "Software"),
 
6
 * to deal in the Software without restriction, including without limitation
 
7
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
8
 * and/or sell copies of the Software, and to permit persons to whom the
 
9
 * Software is furnished to do so, subject to the following conditions:
 
10
 *
 
11
 * The above copyright notice and this permission notice shall be included
 
12
 * in all copies or substantial portions of the Software.
 
13
 *
 
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
15
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 
17
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
18
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
19
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
20
 * DEALINGS IN THE SOFTWARE.
 
21
 ******************************************************************************
 
22
 *
 
23
 * cpl_port.h
 
24
 *
 
25
 * Include file providing low level portability services for CPL.  This
 
26
 * should be the first include file for any CPL based code.  It provides the
 
27
 * following:
 
28
 *
 
29
 * o Includes some standard system include files, such as stdio, and stdlib.
 
30
 *
 
31
 * o Defines CPL_C_START, CPL_C_END macros.
 
32
 *
 
33
 * o Ensures that some other standard macros like NULL are defined.
 
34
 *
 
35
 * o Defines some portability stuff like CPL_MSB, or CPL_LSB.
 
36
 *
 
37
 * o Ensures that core types such as GBool, GInt32, GInt16, GUInt32, 
 
38
 *   GUInt16, and GByte are defined.
 
39
 *
 
40
 * $Log: cpl_port.h,v $
 
41
 * Revision 1.9  1999/02/17 01:41:17  warmerda
 
42
 * Added NULL.
 
43
 *
 
44
 * Revision 1.8  1999/02/02 21:32:38  warmerda
 
45
 * Added CPL_{MSB,LSB}WORD{16,32} macros.
 
46
 *
 
47
 * Revision 1.7  1999/02/02 19:02:36  warmerda
 
48
 * Removed duplicates of base types, and CPL_LSB
 
49
 *
 
50
 * Revision 1.6  1999/01/28 18:36:06  warmerda
 
51
 * Ensure WIN32 is defined on Windows.
 
52
 *
 
53
 * Revision 1.5  1999/01/28 05:26:12  danmo
 
54
 * Added byte swapping macros.
 
55
 *
 
56
 * Revision 1.4  1998/12/15 19:05:30  warmerda
 
57
 * added errno.h
 
58
 *
 
59
 * Revision 1.3  1998/12/14 04:50:07  warmerda
 
60
 * Added DBMALLOC support
 
61
 *
 
62
 * Revision 1.2  1998/12/04 21:38:40  danmo
 
63
 * Changed str*casecmp() to str*icmp() for WIN32
 
64
 *
 
65
 * Revision 1.1  1998/12/03 18:26:02  warmerda
 
66
 * New
 
67
 *
 
68
 */
 
69
 
 
70
#ifndef CPL_BASE_H_INCLUDED
 
71
#define CPL_BASE_H_INCLUDED
 
72
 
 
73
/* ==================================================================== */
 
74
/*      We will use WIN32 as a standard windows define.                 */
 
75
/* ==================================================================== */
 
76
#if defined(_WIN32) && !defined(WIN32)
 
77
#  define WIN32
 
78
#endif
 
79
 
 
80
/* ==================================================================== */
 
81
/*      Standard include files.                                         */
 
82
/* ==================================================================== */
 
83
 
 
84
#include <stdio.h>
 
85
#include <stdlib.h>
 
86
#include <math.h>
 
87
#include <stdarg.h>
 
88
#include <string.h>
 
89
#include <errno.h>
 
90
 
 
91
#ifdef DBMALLOC
 
92
#include <dbmalloc.h>
 
93
#endif
 
94
 
 
95
/* ==================================================================== */
 
96
/*      Base portability stuff ... this stuff may need to be            */
 
97
/*      modified for new platforms.                                     */
 
98
/* ==================================================================== */
 
99
 
 
100
/*---------------------------------------------------------------------
 
101
 *        types for 16 and 32 bits integers, etc...
 
102
 *--------------------------------------------------------------------*/
 
103
#if UINT_MAX == 65535
 
104
typedef long            GInt32;
 
105
typedef unsigned long   GUInt32;
 
106
#else
 
107
typedef int             GInt32;
 
108
typedef unsigned int    GUInt32;
 
109
#endif
 
110
 
 
111
typedef short           GInt16;
 
112
typedef unsigned short  GUInt16;
 
113
typedef unsigned char   GByte;
 
114
typedef int             GBool;
 
115
 
 
116
 
 
117
/* ==================================================================== */
 
118
/*      Other standard services.                                        */
 
119
/* ==================================================================== */
 
120
#ifdef __cplusplus
 
121
#  define CPL_C_START           extern "C" {
 
122
#  define CPL_C_END             }
 
123
#else
 
124
#  define CPL_C_START
 
125
#  define CPL_C_END
 
126
#endif
 
127
 
 
128
/* #  define CPL_DLL     __declspec(dllexport) */
 
129
 
 
130
#define CPL_DLL
 
131
 
 
132
#ifndef NULL
 
133
#  define NULL  0
 
134
#endif
 
135
 
 
136
#ifndef FALSE
 
137
#  define FALSE 0
 
138
#endif
 
139
 
 
140
#ifndef TRUE
 
141
#  define TRUE  1
 
142
#endif
 
143
 
 
144
#ifndef MAX
 
145
#  define MIN(a,b)      ((a<b) ? a : b)
 
146
#  define MAX(a,b)      ((a>b) ? a : b)
 
147
#endif
 
148
 
 
149
#ifndef NULL
 
150
#define NULL 0
 
151
#endif
 
152
 
 
153
#ifndef ABS
 
154
#  define ABS(x)        ((x<0) ? (-1*(x)) : x)
 
155
#endif
 
156
 
 
157
#ifndef EQUAL
 
158
#ifdef WIN32
 
159
#  define EQUALN(a,b,n)           (strnicmp(a,b,n)==0)
 
160
#  define EQUAL(a,b)              (stricmp(a,b)==0)
 
161
#else
 
162
#  define EQUALN(a,b,n)           (strncasecmp(a,b,n)==0)
 
163
#  define EQUAL(a,b)              (strcasecmp(a,b)==0)
 
164
#endif
 
165
#endif
 
166
 
 
167
/*---------------------------------------------------------------------
 
168
 *                         CPL_LSB and CPL_MSB
 
169
 * Only one of these 2 macros should be defined and specifies the byte 
 
170
 * ordering for the current platform.  
 
171
 * This should be defined in the Makefile, but if it is not then
 
172
 * the default is CPL_LSB (Intel ordering, LSB first).
 
173
 *--------------------------------------------------------------------*/
 
174
#if ! ( defined(CPL_LSB) || defined(CPL_MSB) )
 
175
#define CPL_LSB
 
176
#endif
 
177
 
 
178
/*---------------------------------------------------------------------
 
179
 *        Little endian <==> big endian byte swap macros.
 
180
 *--------------------------------------------------------------------*/
 
181
 
 
182
#define CPL_SWAP16(x) \
 
183
        ((GUInt16)( \
 
184
            (((GUInt16)(x) & 0x00ffU) << 8) | \
 
185
            (((GUInt16)(x) & 0xff00U) >> 8) ))
 
186
 
 
187
#define CPL_SWAP32(x) \
 
188
        ((GUInt32)( \
 
189
            (((GUInt32)(x) & (GUInt32)0x000000ffUL) << 24) | \
 
190
            (((GUInt32)(x) & (GUInt32)0x0000ff00UL) <<  8) | \
 
191
            (((GUInt32)(x) & (GUInt32)0x00ff0000UL) >>  8) | \
 
192
            (((GUInt32)(x) & (GUInt32)0xff000000UL) >> 24) ))
 
193
 
 
194
/* Until we have a safe 64 bits integer data type defined, we'll replace
 
195
m * this version of the CPL_SWAP64() macro with a less efficient one.
 
196
 */
 
197
/*
 
198
#define CPL_SWAP64(x) \
 
199
        ((uint64)( \
 
200
            (uint64)(((uint64)(x) & (uint64)0x00000000000000ffULL) << 56) | \
 
201
            (uint64)(((uint64)(x) & (uint64)0x000000000000ff00ULL) << 40) | \
 
202
            (uint64)(((uint64)(x) & (uint64)0x0000000000ff0000ULL) << 24) | \
 
203
            (uint64)(((uint64)(x) & (uint64)0x00000000ff000000ULL) << 8) | \
 
204
            (uint64)(((uint64)(x) & (uint64)0x000000ff00000000ULL) >> 8) | \
 
205
            (uint64)(((uint64)(x) & (uint64)0x0000ff0000000000ULL) >> 24) | \
 
206
            (uint64)(((uint64)(x) & (uint64)0x00ff000000000000ULL) >> 40) | \
 
207
            (uint64)(((uint64)(x) & (uint64)0xff00000000000000ULL) >> 56) ))
 
208
*/
 
209
 
 
210
#define CPL_SWAPDOUBLE(p) {                             \
 
211
        double _tmp = *(double *)(p);                     \
 
212
        ((GByte *)(p))[0] = ((GByte *)&_tmp)[7];          \
 
213
        ((GByte *)(p))[1] = ((GByte *)&_tmp)[6];          \
 
214
        ((GByte *)(p))[2] = ((GByte *)&_tmp)[5];          \
 
215
        ((GByte *)(p))[3] = ((GByte *)&_tmp)[4];          \
 
216
        ((GByte *)(p))[4] = ((GByte *)&_tmp)[3];          \
 
217
        ((GByte *)(p))[5] = ((GByte *)&_tmp)[2];          \
 
218
        ((GByte *)(p))[6] = ((GByte *)&_tmp)[1];          \
 
219
        ((GByte *)(p))[7] = ((GByte *)&_tmp)[0];          \
 
220
}
 
221
 
 
222
#ifdef CPL_MSB
 
223
#  define CPL_MSBWORD16(x)      (x)
 
224
#  define CPL_LSBWORD16(x)      CPL_SWAP16(x)
 
225
#  define CPL_MSBWORD32(x)      (x)
 
226
#  define CPL_LSBWORD32(x)      CPL_SWAP32(x)
 
227
#else
 
228
#  define CPL_LSBWORD16(x)      (x)
 
229
#  define CPL_MSBWORD16(x)      CPL_SWAP16(x)
 
230
#  define CPL_LSBWORD32(x)      (x)
 
231
#  define CPL_MSBWORD32(x)      CPL_SWAP32(x)
 
232
#endif
 
233
 
 
234
#endif /* ndef CPL_BASE_H_INCLUDED */