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