svn-gvsig-desktop / trunk / libraries / libjni-gdal / include / cpl_port.h @ 716
History | View | Annotate | Download (14.4 KB)
1 |
/******************************************************************************
|
---|---|
2 |
* $Id: cpl_port.h 716 2004-12-28 14:07:11Z igbrotru $
|
3 |
*
|
4 |
* Project: CPL - Common Portability Library
|
5 |
* Author: Frank Warmerdam, warmerdam@pobox.com
|
6 |
* Purpose:
|
7 |
* Include file providing low level portability services for CPL. This
|
8 |
* should be the first include file for any CPL based code. It provides the
|
9 |
* following:
|
10 |
*
|
11 |
* o Includes some standard system include files, such as stdio, and stdlib.
|
12 |
*
|
13 |
* o Defines CPL_C_START, CPL_C_END macros.
|
14 |
*
|
15 |
* o Ensures that some other standard macros like NULL are defined.
|
16 |
*
|
17 |
* o Defines some portability stuff like CPL_MSB, or CPL_LSB.
|
18 |
*
|
19 |
* o Ensures that core types such as GBool, GInt32, GInt16, GUInt32,
|
20 |
* GUInt16, and GByte are defined.
|
21 |
*
|
22 |
******************************************************************************
|
23 |
* Copyright (c) 1998, Frank Warmerdam
|
24 |
*
|
25 |
* Permission is hereby granted, free of charge, to any person obtaining a
|
26 |
* copy of this software and associated documentation files (the "Software"),
|
27 |
* to deal in the Software without restriction, including without limitation
|
28 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
29 |
* and/or sell copies of the Software, and to permit persons to whom the
|
30 |
* Software is furnished to do so, subject to the following conditions:
|
31 |
*
|
32 |
* The above copyright notice and this permission notice shall be included
|
33 |
* in all copies or substantial portions of the Software.
|
34 |
*
|
35 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
36 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
37 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
38 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
39 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
40 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
41 |
* DEALINGS IN THE SOFTWARE.
|
42 |
******************************************************************************
|
43 |
*
|
44 |
* $Log$
|
45 |
* Revision 1.1 2004-12-28 14:06:59 igbrotru
|
46 |
* *** empty log message ***
|
47 |
*
|
48 |
* Revision 1.1 2004/10/28 12:08:47 igbrotru
|
49 |
* *** empty log message ***
|
50 |
*
|
51 |
* Revision 1.1 2004/09/27 08:27:48 igbrotru
|
52 |
* *** empty log message ***
|
53 |
*
|
54 |
* Revision 1.1 2004/09/08 12:39:04 igbrotru
|
55 |
* *** empty log message ***
|
56 |
*
|
57 |
* Revision 1.36 2004/01/06 21:42:32 warmerda
|
58 |
* "Fix" for bug 455 related to CPL_IS_LSB macro.
|
59 |
*
|
60 |
* Revision 1.35 2003/12/11 03:16:02 warmerda
|
61 |
* Added CPL_IS_LSB macro with value 0 (MSB) or 1 (LSB).
|
62 |
*
|
63 |
* Revision 1.34 2003/09/08 11:11:05 dron
|
64 |
* Include time.h and locale.h.
|
65 |
*
|
66 |
* Revision 1.33 2003/05/12 14:52:56 warmerda
|
67 |
* Use _MSC_VER to test for Microsoft Visual C++ compiler.
|
68 |
*
|
69 |
* Revision 1.32 2002/10/24 20:24:40 warmerda
|
70 |
* avoid using variable names likely to conflict in macros
|
71 |
*
|
72 |
* Revision 1.31 2002/07/15 13:31:46 warmerda
|
73 |
* CPL_SWAPDOUBLE had alignment problem, use CPL_SWAP64PTR
|
74 |
*
|
75 |
* Revision 1.30 2002/04/18 18:55:06 dron
|
76 |
* added <ctype.h> at the list of standard include files
|
77 |
*
|
78 |
* Revision 1.29 2002/01/17 01:40:27 warmerda
|
79 |
* added _LARGEFILE64_SOURCE support
|
80 |
*
|
81 |
* Revision 1.28 2001/08/30 21:20:49 warmerda
|
82 |
* expand tabs
|
83 |
*
|
84 |
* Revision 1.27 2001/07/18 04:00:49 warmerda
|
85 |
* added CPL_CVSID
|
86 |
*
|
87 |
* Revision 1.26 2001/06/21 21:17:26 warmerda
|
88 |
* added irix 64bit file api support
|
89 |
*
|
90 |
* Revision 1.25 2001/04/30 18:18:38 warmerda
|
91 |
* added macos support, standard header
|
92 |
*
|
93 |
* Revision 1.24 2001/01/19 21:16:41 warmerda
|
94 |
* expanded tabs
|
95 |
*
|
96 |
* Revision 1.23 2001/01/13 04:06:39 warmerda
|
97 |
* added strings.h on AIX as per patch from Dale.
|
98 |
*
|
99 |
* Revision 1.22 2001/01/03 16:18:07 warmerda
|
100 |
* added GUIntBig
|
101 |
*
|
102 |
* Revision 1.21 2000/10/20 04:20:33 warmerda
|
103 |
* added SWAP16PTR macros
|
104 |
*
|
105 |
* Revision 1.20 2000/10/13 17:32:42 warmerda
|
106 |
* check for unix instead of IGNORE_WIN32
|
107 |
*
|
108 |
* Revision 1.19 2000/09/25 19:58:43 warmerda
|
109 |
* ensure win32 doesn't get defined in Cygnus builds
|
110 |
*
|
111 |
* Revision 1.18 2000/07/20 13:15:03 warmerda
|
112 |
* don't redeclare CPL_DLL
|
113 |
*/
|
114 |
|
115 |
#ifndef CPL_BASE_H_INCLUDED
|
116 |
#define CPL_BASE_H_INCLUDED
|
117 |
|
118 |
/**
|
119 |
* \file cpl_port.h
|
120 |
*
|
121 |
* Core portability definitions for CPL.
|
122 |
*
|
123 |
*/
|
124 |
|
125 |
/* ==================================================================== */
|
126 |
/* We will use macos_pre10 to indicate compilation with MacOS */
|
127 |
/* versions before MacOS X. */
|
128 |
/* ==================================================================== */
|
129 |
#ifdef macintosh
|
130 |
# define macos_pre10
|
131 |
#endif
|
132 |
|
133 |
/* ==================================================================== */
|
134 |
/* We will use WIN32 as a standard windows define. */
|
135 |
/* ==================================================================== */
|
136 |
#if defined(_WIN32) && !defined(WIN32)
|
137 |
# define WIN32
|
138 |
#endif
|
139 |
|
140 |
#if defined(_WINDOWS) && !defined(WIN32)
|
141 |
# define WIN32
|
142 |
#endif
|
143 |
|
144 |
#include "cpl_config.h" |
145 |
|
146 |
/* ==================================================================== */
|
147 |
/* This will disable most WIN32 stuff in a Cygnus build which */
|
148 |
/* defines unix to 1. */
|
149 |
/* ==================================================================== */
|
150 |
|
151 |
#ifdef unix
|
152 |
# undef WIN32
|
153 |
#endif
|
154 |
|
155 |
#if defined(VSI_NEED_LARGEFILE64_SOURCE) && !defined(_LARGEFILE64_SOURCE)
|
156 |
# define _LARGEFILE64_SOURCE 1 |
157 |
#endif
|
158 |
|
159 |
/* ==================================================================== */
|
160 |
/* Standard include files. */
|
161 |
/* ==================================================================== */
|
162 |
|
163 |
#include <stdio.h> |
164 |
#include <stdlib.h> |
165 |
#include <math.h> |
166 |
#include <stdarg.h> |
167 |
#include <string.h> |
168 |
#include <ctype.h> |
169 |
#include <errno.h> |
170 |
#include <time.h> |
171 |
|
172 |
#ifdef HAVE_LOCALE_H
|
173 |
# include <locale.h> |
174 |
#endif
|
175 |
|
176 |
#ifdef _AIX
|
177 |
# include <strings.h> |
178 |
#endif
|
179 |
|
180 |
#if defined(HAVE_LIBDBMALLOC) && defined(HAVE_DBMALLOC_H) && defined(DEBUG)
|
181 |
# define DBMALLOC
|
182 |
# include <dbmalloc.h> |
183 |
#endif
|
184 |
|
185 |
#if !defined(DBMALLOC) && defined(HAVE_DMALLOC_H)
|
186 |
# define USE_DMALLOC
|
187 |
# include <dmalloc.h> |
188 |
#endif
|
189 |
|
190 |
/* ==================================================================== */
|
191 |
/* Base portability stuff ... this stuff may need to be */
|
192 |
/* modified for new platforms. */
|
193 |
/* ==================================================================== */
|
194 |
|
195 |
/*---------------------------------------------------------------------
|
196 |
* types for 16 and 32 bits integers, etc...
|
197 |
*--------------------------------------------------------------------*/
|
198 |
#if UINT_MAX == 65535 |
199 |
typedef long GInt32; |
200 |
typedef unsigned long GUInt32; |
201 |
#else
|
202 |
typedef int GInt32; |
203 |
typedef unsigned int GUInt32; |
204 |
#endif
|
205 |
|
206 |
typedef short GInt16; |
207 |
typedef unsigned short GUInt16; |
208 |
typedef unsigned char GByte; |
209 |
typedef int GBool; |
210 |
|
211 |
/* -------------------------------------------------------------------- */
|
212 |
/* 64bit support */
|
213 |
/* -------------------------------------------------------------------- */
|
214 |
|
215 |
#if defined(WIN32) && defined(_MSC_VER)
|
216 |
|
217 |
#define VSI_LARGE_API_SUPPORTED
|
218 |
typedef __int64 GIntBig;
|
219 |
typedef unsigned __int64 GUIntBig; |
220 |
|
221 |
#elif HAVE_LONG_LONG
|
222 |
|
223 |
typedef long long GIntBig; |
224 |
typedef unsigned long long GUIntBig; |
225 |
|
226 |
#else
|
227 |
|
228 |
typedef long GIntBig; |
229 |
typedef unsigned long GUIntBig; |
230 |
|
231 |
#endif
|
232 |
|
233 |
/* ==================================================================== */
|
234 |
/* Other standard services. */
|
235 |
/* ==================================================================== */
|
236 |
#ifdef __cplusplus
|
237 |
# define CPL_C_START extern "C" { |
238 |
# define CPL_C_END }
|
239 |
#else
|
240 |
# define CPL_C_START
|
241 |
# define CPL_C_END
|
242 |
#endif
|
243 |
|
244 |
#ifndef CPL_DLL
|
245 |
#if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
|
246 |
# define CPL_DLL __declspec(dllexport)
|
247 |
#else
|
248 |
# define CPL_DLL
|
249 |
#endif
|
250 |
#endif
|
251 |
|
252 |
|
253 |
#ifndef NULL |
254 |
# define NULL 0 |
255 |
#endif
|
256 |
|
257 |
#ifndef FALSE
|
258 |
# define FALSE 0 |
259 |
#endif
|
260 |
|
261 |
#ifndef TRUE
|
262 |
# define TRUE 1 |
263 |
#endif
|
264 |
|
265 |
#ifndef MAX
|
266 |
# define MIN(a,b) ((a<b) ? a : b)
|
267 |
# define MAX(a,b) ((a>b) ? a : b)
|
268 |
#endif
|
269 |
|
270 |
#ifndef ABS
|
271 |
# define ABS(x) ((x<0) ? (-1*(x)) : x) |
272 |
#endif
|
273 |
|
274 |
#ifndef EQUAL
|
275 |
#ifdef WIN32
|
276 |
# define EQUALN(a,b,n) (strnicmp(a,b,n)==0) |
277 |
# define EQUAL(a,b) (stricmp(a,b)==0) |
278 |
#else
|
279 |
# define EQUALN(a,b,n) (strncasecmp(a,b,n)==0) |
280 |
# define EQUAL(a,b) (strcasecmp(a,b)==0) |
281 |
#endif
|
282 |
#endif
|
283 |
|
284 |
#ifdef macos_pre10
|
285 |
int strcasecmp(char * str1, char * str2); |
286 |
int strncasecmp(char * str1, char * str2, int len); |
287 |
char * strdup (char *instr); |
288 |
#endif
|
289 |
|
290 |
/*---------------------------------------------------------------------
|
291 |
* CPL_LSB and CPL_MSB
|
292 |
* Only one of these 2 macros should be defined and specifies the byte
|
293 |
* ordering for the current platform.
|
294 |
* This should be defined in the Makefile, but if it is not then
|
295 |
* the default is CPL_LSB (Intel ordering, LSB first).
|
296 |
*--------------------------------------------------------------------*/
|
297 |
#if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
|
298 |
# define CPL_MSB
|
299 |
#endif
|
300 |
|
301 |
#if ! ( defined(CPL_LSB) || defined(CPL_MSB) )
|
302 |
#define CPL_LSB
|
303 |
#endif
|
304 |
|
305 |
#if defined(CPL_LSB)
|
306 |
# define CPL_IS_LSB 1 |
307 |
#else
|
308 |
# define CPL_IS_LSB 0 |
309 |
#endif
|
310 |
|
311 |
/*---------------------------------------------------------------------
|
312 |
* Little endian <==> big endian byte swap macros.
|
313 |
*--------------------------------------------------------------------*/
|
314 |
|
315 |
#define CPL_SWAP16(x) \
|
316 |
((GUInt16)( \ |
317 |
(((GUInt16)(x) & 0x00ffU) << 8) | \ |
318 |
(((GUInt16)(x) & 0xff00U) >> 8) )) |
319 |
|
320 |
#define CPL_SWAP16PTR(x) \
|
321 |
{ \ |
322 |
GByte byTemp, *_pabyDataT = (GByte *) (x); \ |
323 |
\ |
324 |
byTemp = _pabyDataT[0]; \
|
325 |
_pabyDataT[0] = _pabyDataT[1]; \ |
326 |
_pabyDataT[1] = byTemp; \
|
327 |
} |
328 |
|
329 |
#define CPL_SWAP32(x) \
|
330 |
((GUInt32)( \ |
331 |
(((GUInt32)(x) & (GUInt32)0x000000ffUL) << 24) | \ |
332 |
(((GUInt32)(x) & (GUInt32)0x0000ff00UL) << 8) | \ |
333 |
(((GUInt32)(x) & (GUInt32)0x00ff0000UL) >> 8) | \ |
334 |
(((GUInt32)(x) & (GUInt32)0xff000000UL) >> 24) )) |
335 |
|
336 |
#define CPL_SWAP32PTR(x) \
|
337 |
{ \ |
338 |
GByte byTemp, *_pabyDataT = (GByte *) (x); \ |
339 |
\ |
340 |
byTemp = _pabyDataT[0]; \
|
341 |
_pabyDataT[0] = _pabyDataT[3]; \ |
342 |
_pabyDataT[3] = byTemp; \
|
343 |
byTemp = _pabyDataT[1]; \
|
344 |
_pabyDataT[1] = _pabyDataT[2]; \ |
345 |
_pabyDataT[2] = byTemp; \
|
346 |
} |
347 |
|
348 |
#define CPL_SWAP64PTR(x) \
|
349 |
{ \ |
350 |
GByte byTemp, *_pabyDataT = (GByte *) (x); \ |
351 |
\ |
352 |
byTemp = _pabyDataT[0]; \
|
353 |
_pabyDataT[0] = _pabyDataT[7]; \ |
354 |
_pabyDataT[7] = byTemp; \
|
355 |
byTemp = _pabyDataT[1]; \
|
356 |
_pabyDataT[1] = _pabyDataT[6]; \ |
357 |
_pabyDataT[6] = byTemp; \
|
358 |
byTemp = _pabyDataT[2]; \
|
359 |
_pabyDataT[2] = _pabyDataT[5]; \ |
360 |
_pabyDataT[5] = byTemp; \
|
361 |
byTemp = _pabyDataT[3]; \
|
362 |
_pabyDataT[3] = _pabyDataT[4]; \ |
363 |
_pabyDataT[4] = byTemp; \
|
364 |
} |
365 |
|
366 |
|
367 |
/* Until we have a safe 64 bits integer data type defined, we'll replace
|
368 |
m * this version of the CPL_SWAP64() macro with a less efficient one.
|
369 |
*/
|
370 |
/*
|
371 |
#define CPL_SWAP64(x) \
|
372 |
((uint64)( \
|
373 |
(uint64)(((uint64)(x) & (uint64)0x00000000000000ffULL) << 56) | \
|
374 |
(uint64)(((uint64)(x) & (uint64)0x000000000000ff00ULL) << 40) | \
|
375 |
(uint64)(((uint64)(x) & (uint64)0x0000000000ff0000ULL) << 24) | \
|
376 |
(uint64)(((uint64)(x) & (uint64)0x00000000ff000000ULL) << 8) | \
|
377 |
(uint64)(((uint64)(x) & (uint64)0x000000ff00000000ULL) >> 8) | \
|
378 |
(uint64)(((uint64)(x) & (uint64)0x0000ff0000000000ULL) >> 24) | \
|
379 |
(uint64)(((uint64)(x) & (uint64)0x00ff000000000000ULL) >> 40) | \
|
380 |
(uint64)(((uint64)(x) & (uint64)0xff00000000000000ULL) >> 56) ))
|
381 |
*/
|
382 |
|
383 |
#define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
|
384 |
|
385 |
#ifdef CPL_MSB
|
386 |
# define CPL_MSBWORD16(x) (x)
|
387 |
# define CPL_LSBWORD16(x) CPL_SWAP16(x)
|
388 |
# define CPL_MSBWORD32(x) (x)
|
389 |
# define CPL_LSBWORD32(x) CPL_SWAP32(x)
|
390 |
# define CPL_MSBPTR16(x)
|
391 |
# define CPL_LSBPTR16(x) CPL_SWAP16PTR(x)
|
392 |
# define CPL_MSBPTR32(x)
|
393 |
# define CPL_LSBPTR32(x) CPL_SWAP32PTR(x)
|
394 |
# define CPL_MSBPTR64(x)
|
395 |
# define CPL_LSBPTR64(x) CPL_SWAP64PTR(x)
|
396 |
#else
|
397 |
# define CPL_LSBWORD16(x) (x)
|
398 |
# define CPL_MSBWORD16(x) CPL_SWAP16(x)
|
399 |
# define CPL_LSBWORD32(x) (x)
|
400 |
# define CPL_MSBWORD32(x) CPL_SWAP32(x)
|
401 |
# define CPL_LSBPTR16(x)
|
402 |
# define CPL_MSBPTR16(x) CPL_SWAP16PTR(x)
|
403 |
# define CPL_LSBPTR32(x)
|
404 |
# define CPL_MSBPTR32(x) CPL_SWAP32PTR(x)
|
405 |
# define CPL_LSBPTR64(x)
|
406 |
# define CPL_MSBPTR64(x) CPL_SWAP64PTR(x)
|
407 |
#endif
|
408 |
|
409 |
/***********************************************************************
|
410 |
* Define CPL_CVSID() macro. It can be disabled during a build by
|
411 |
* defining DISABLE_CPLID in the compiler options.
|
412 |
*
|
413 |
* The cvsid_aw() function is just there to prevent reports of cpl_cvsid()
|
414 |
* being unused.
|
415 |
*/
|
416 |
|
417 |
#ifndef DISABLE_CVSID
|
418 |
# define CPL_CVSID(string) static char cpl_cvsid[] = string; \ |
419 |
static char *cvsid_aw() { return( cvsid_aw() ? ((char *) NULL) : cpl_cvsid ); } |
420 |
#else
|
421 |
# define CPL_CVSID(string)
|
422 |
#endif
|
423 |
|
424 |
#endif /* ndef CPL_BASE_H_INCLUDED */ |