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