cpl_port.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /******************************************************************************
  2. * $Id: cpl_port.h 29925 2015-08-30 12:05:05Z rouault $
  3. *
  4. * Project: CPL - Common Portability Library
  5. * Author: Frank Warmerdam, warmerdam@pobox.com
  6. * Purpose: Include file providing low level portability services for CPL.
  7. * This should be the first include file for any CPL based code.
  8. *
  9. ******************************************************************************
  10. * Copyright (c) 1998, 2005, Frank Warmerdam <warmerdam@pobox.com>
  11. * Copyright (c) 2008-2013, Even Rouault <even dot rouault at mines-paris dot org>
  12. *
  13. * Permission is hereby granted, free of charge, to any person obtaining a
  14. * copy of this software and associated documentation files (the "Software"),
  15. * to deal in the Software without restriction, including without limitation
  16. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  17. * and/or sell copies of the Software, and to permit persons to whom the
  18. * Software is furnished to do so, subject to the following conditions:
  19. *
  20. * The above copyright notice and this permission notice shall be included
  21. * in all copies or substantial portions of the Software.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  24. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  26. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  28. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  29. * DEALINGS IN THE SOFTWARE.
  30. ****************************************************************************/
  31. #ifndef CPL_BASE_H_INCLUDED
  32. #define CPL_BASE_H_INCLUDED
  33. /**
  34. * \file cpl_port.h
  35. *
  36. * Core portability definitions for CPL.
  37. *
  38. */
  39. /* ==================================================================== */
  40. /* We will use macos_pre10 to indicate compilation with MacOS */
  41. /* versions before MacOS X. */
  42. /* ==================================================================== */
  43. #ifdef macintosh
  44. # define macos_pre10
  45. #endif
  46. /* ==================================================================== */
  47. /* We will use WIN32 as a standard windows define. */
  48. /* ==================================================================== */
  49. #if defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE)
  50. # define WIN32
  51. #endif
  52. #if defined(_WINDOWS) && !defined(WIN32) && !defined(_WIN32_WCE)
  53. # define WIN32
  54. #endif
  55. /* ==================================================================== */
  56. /* We will use WIN32CE as a standard Windows CE (Mobile) define. */
  57. /* ==================================================================== */
  58. #if defined(_WIN32_WCE)
  59. # define WIN32CE
  60. #endif
  61. /* -------------------------------------------------------------------- */
  62. /* The following apparently allow you to use strcpy() and other */
  63. /* functions judged "unsafe" by microsoft in VS 8 (2005). */
  64. /* -------------------------------------------------------------------- */
  65. #ifdef _MSC_VER
  66. # ifndef _CRT_SECURE_NO_DEPRECATE
  67. # define _CRT_SECURE_NO_DEPRECATE
  68. # endif
  69. # ifndef _CRT_NONSTDC_NO_DEPRECATE
  70. # define _CRT_NONSTDC_NO_DEPRECATE
  71. # endif
  72. #endif
  73. #include "cpl_config.h"
  74. /* ==================================================================== */
  75. /* A few sanity checks, mainly to detect problems that sometimes */
  76. /* arise with bad configured cross-compilation. */
  77. /* ==================================================================== */
  78. #if !defined(SIZEOF_INT) || SIZEOF_INT != 4
  79. #error "Unexpected value for SIZEOF_INT"
  80. #endif
  81. #if !defined(SIZEOF_UNSIGNED_LONG) || (SIZEOF_UNSIGNED_LONG != 4 && SIZEOF_UNSIGNED_LONG != 8)
  82. #error "Unexpected value for SIZEOF_UNSIGNED_LONG"
  83. #endif
  84. #if !defined(SIZEOF_VOIDP) || (SIZEOF_VOIDP != 4 && SIZEOF_VOIDP != 8)
  85. #error "Unexpected value for SIZEOF_VOIDP"
  86. #endif
  87. /* ==================================================================== */
  88. /* This will disable most WIN32 stuff in a Cygnus build which */
  89. /* defines unix to 1. */
  90. /* ==================================================================== */
  91. #ifdef unix
  92. # undef WIN32
  93. # undef WIN32CE
  94. #endif
  95. #if defined(VSI_NEED_LARGEFILE64_SOURCE) && !defined(_LARGEFILE64_SOURCE)
  96. # define _LARGEFILE64_SOURCE 1
  97. #endif
  98. /* ==================================================================== */
  99. /* If iconv() is available use extended recoding module. */
  100. /* Stub implementation is always compiled in, because it works */
  101. /* faster than iconv() for encodings it supports. */
  102. /* ==================================================================== */
  103. #if defined(HAVE_ICONV)
  104. # define CPL_RECODE_ICONV
  105. #endif
  106. #define CPL_RECODE_STUB
  107. /* ==================================================================== */
  108. /* MinGW stuff */
  109. /* ==================================================================== */
  110. /* We need __MSVCRT_VERSION__ >= 0x0601 to have "struct __stat64" */
  111. /* Latest versions of mingw32 define it, but with older ones, */
  112. /* we need to define it manually */
  113. #if defined(__MINGW32__)
  114. #ifndef __MSVCRT_VERSION__
  115. #define __MSVCRT_VERSION__ 0x0601
  116. #endif
  117. #endif
  118. /* ==================================================================== */
  119. /* Standard include files. */
  120. /* ==================================================================== */
  121. #include <stdio.h>
  122. #include <stdlib.h>
  123. #include <math.h>
  124. #include <stdarg.h>
  125. #include <string.h>
  126. #include <ctype.h>
  127. #include <limits.h>
  128. #if !defined(WIN32CE)
  129. # include <time.h>
  130. #else
  131. # include <wce_time.h>
  132. # include <wce_errno.h>
  133. #endif
  134. #if defined(HAVE_ERRNO_H)
  135. # include <errno.h>
  136. #endif
  137. #ifdef HAVE_LOCALE_H
  138. # include <locale.h>
  139. #endif
  140. #ifdef HAVE_DIRECT_H
  141. # include <direct.h>
  142. #endif
  143. #if !(defined(WIN32) || defined(WIN32CE))
  144. # include <strings.h>
  145. #endif
  146. #if defined(HAVE_LIBDBMALLOC) && defined(HAVE_DBMALLOC_H) && defined(DEBUG)
  147. # define DBMALLOC
  148. # include <dbmalloc.h>
  149. #endif
  150. #if !defined(DBMALLOC) && defined(HAVE_DMALLOC_H)
  151. # define USE_DMALLOC
  152. # include <dmalloc.h>
  153. #endif
  154. /* ==================================================================== */
  155. /* Base portability stuff ... this stuff may need to be */
  156. /* modified for new platforms. */
  157. /* ==================================================================== */
  158. /*---------------------------------------------------------------------
  159. * types for 16 and 32 bits integers, etc...
  160. *--------------------------------------------------------------------*/
  161. #if UINT_MAX == 65535
  162. typedef long GInt32;
  163. typedef unsigned long GUInt32;
  164. #else
  165. typedef int GInt32;
  166. typedef unsigned int GUInt32;
  167. #endif
  168. typedef short GInt16;
  169. typedef unsigned short GUInt16;
  170. typedef unsigned char GByte;
  171. /* hack for PDF driver and poppler >= 0.15.0 that defines incompatible "typedef bool GBool" */
  172. /* in include/poppler/goo/gtypes.h */
  173. #ifndef CPL_GBOOL_DEFINED
  174. #define CPL_GBOOL_DEFINED
  175. typedef int GBool;
  176. #endif
  177. /* -------------------------------------------------------------------- */
  178. /* 64bit support */
  179. /* -------------------------------------------------------------------- */
  180. #if defined(WIN32) && defined(_MSC_VER)
  181. #define VSI_LARGE_API_SUPPORTED
  182. typedef __int64 GIntBig;
  183. typedef unsigned __int64 GUIntBig;
  184. #define GINTBIG_MIN ((GIntBig)(0x80000000) << 32)
  185. #define GINTBIG_MAX (((GIntBig)(0x7FFFFFFF) << 32) | 0xFFFFFFFFU)
  186. #elif HAVE_LONG_LONG
  187. typedef long long GIntBig;
  188. typedef unsigned long long GUIntBig;
  189. #define GINTBIG_MIN ((GIntBig)(0x80000000) << 32)
  190. #define GINTBIG_MAX (((GIntBig)(0x7FFFFFFF) << 32) | 0xFFFFFFFFU)
  191. #else
  192. typedef long GIntBig;
  193. typedef unsigned long GUIntBig;
  194. #define GINTBIG_MIN INT_MIN
  195. #define GINTBIG_MAX INT_MAX
  196. #endif
  197. #if SIZEOF_VOIDP == 8
  198. typedef GIntBig GPtrDiff_t;
  199. #else
  200. typedef int GPtrDiff_t;
  201. #endif
  202. #if defined(__MSVCRT__) || (defined(WIN32) && defined(_MSC_VER))
  203. #define CPL_FRMT_GB_WITHOUT_PREFIX "I64"
  204. #elif HAVE_LONG_LONG
  205. #define CPL_FRMT_GB_WITHOUT_PREFIX "ll"
  206. #else
  207. #define CPL_FRMT_GB_WITHOUT_PREFIX "l"
  208. #endif
  209. #define CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"
  210. #define CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"
  211. /* Workaround VC6 bug */
  212. #if defined(_MSC_VER) && (_MSC_VER <= 1200)
  213. #define GUINTBIG_TO_DOUBLE(x) (double)(GIntBig)(x)
  214. #else
  215. #define GUINTBIG_TO_DOUBLE(x) (double)(x)
  216. #endif
  217. /* ==================================================================== */
  218. /* Other standard services. */
  219. /* ==================================================================== */
  220. #ifdef __cplusplus
  221. # define CPL_C_START extern "C" {
  222. # define CPL_C_END }
  223. #else
  224. # define CPL_C_START
  225. # define CPL_C_END
  226. #endif
  227. #ifndef CPL_DLL
  228. #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
  229. # define CPL_DLL __declspec(dllexport)
  230. #else
  231. # if defined(USE_GCC_VISIBILITY_FLAG)
  232. # define CPL_DLL __attribute__ ((visibility("default")))
  233. # else
  234. # define CPL_DLL
  235. # endif
  236. #endif
  237. #endif
  238. /* Should optional (normally private) interfaces be exported? */
  239. #ifdef CPL_OPTIONAL_APIS
  240. # define CPL_ODLL CPL_DLL
  241. #else
  242. # define CPL_ODLL
  243. #endif
  244. #ifndef CPL_STDCALL
  245. #if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL)
  246. # define CPL_STDCALL __stdcall
  247. #else
  248. # define CPL_STDCALL
  249. #endif
  250. #endif
  251. #ifdef _MSC_VER
  252. # define FORCE_CDECL __cdecl
  253. #else
  254. # define FORCE_CDECL
  255. #endif
  256. /* TODO : support for other compilers needed */
  257. #if (defined(__GNUC__) && !defined(__NO_INLINE__)) || defined(_MSC_VER)
  258. #define HAS_CPL_INLINE 1
  259. #define CPL_INLINE __inline
  260. #elif defined(__SUNPRO_CC)
  261. #define HAS_CPL_INLINE 1
  262. #define CPL_INLINE inline
  263. #else
  264. #define CPL_INLINE
  265. #endif
  266. #ifndef NULL
  267. # define NULL 0
  268. #endif
  269. #ifndef FALSE
  270. # define FALSE 0
  271. #endif
  272. #ifndef TRUE
  273. # define TRUE 1
  274. #endif
  275. #ifndef MAX
  276. # define MIN(a,b) ((a<b) ? a : b)
  277. # define MAX(a,b) ((a>b) ? a : b)
  278. #endif
  279. #ifndef ABS
  280. # define ABS(x) ((x<0) ? (-1*(x)) : x)
  281. #endif
  282. #ifndef M_PI
  283. # define M_PI 3.14159265358979323846 /* pi */
  284. #endif
  285. /* -------------------------------------------------------------------- */
  286. /* Macro to test equality of two floating point values. */
  287. /* We use fabs() function instead of ABS() macro to avoid side */
  288. /* effects. */
  289. /* -------------------------------------------------------------------- */
  290. #ifndef CPLIsEqual
  291. # define CPLIsEqual(x,y) (fabs((x) - (y)) < 0.0000000000001)
  292. #endif
  293. /* -------------------------------------------------------------------- */
  294. /* Provide macros for case insensitive string comparisons. */
  295. /* -------------------------------------------------------------------- */
  296. #ifndef EQUAL
  297. # if defined(WIN32) || defined(WIN32CE)
  298. # define STRCASECMP(a,b) (stricmp(a,b))
  299. # define STRNCASECMP(a,b,n) (strnicmp(a,b,n))
  300. # else
  301. # define STRCASECMP(a,b) (strcasecmp(a,b))
  302. # define STRNCASECMP(a,b,n) (strncasecmp(a,b,n))
  303. # endif
  304. # define EQUALN(a,b,n) (STRNCASECMP(a,b,n)==0)
  305. # define EQUAL(a,b) (STRCASECMP(a,b)==0)
  306. #endif
  307. #ifdef macos_pre10
  308. int strcasecmp(char * str1, char * str2);
  309. int strncasecmp(char * str1, char * str2, int len);
  310. char * strdup (char *instr);
  311. #endif
  312. #ifndef CPL_THREADLOCAL
  313. # define CPL_THREADLOCAL
  314. #endif
  315. /* -------------------------------------------------------------------- */
  316. /* Handle isnan() and isinf(). Note that isinf() and isnan() */
  317. /* are supposed to be macros according to C99, defined in math.h */
  318. /* Some systems (ie. Tru64) don't have isinf() at all, so if */
  319. /* the macro is not defined we just assume nothing is infinite. */
  320. /* This may mean we have no real CPLIsInf() on systems with isinf()*/
  321. /* function but no corresponding macro, but I can live with */
  322. /* that since it isn't that important a test. */
  323. /* -------------------------------------------------------------------- */
  324. #ifdef _MSC_VER
  325. # include <float.h>
  326. # define CPLIsNan(x) _isnan(x)
  327. # define CPLIsInf(x) (!_isnan(x) && !_finite(x))
  328. # define CPLIsFinite(x) _finite(x)
  329. #else
  330. # define CPLIsNan(x) isnan(x)
  331. # ifdef isinf
  332. # define CPLIsInf(x) isinf(x)
  333. # define CPLIsFinite(x) (!isnan(x) && !isinf(x))
  334. # else
  335. # define CPLIsInf(x) FALSE
  336. # define CPLIsFinite(x) (!isnan(x))
  337. # endif
  338. #endif
  339. /*---------------------------------------------------------------------
  340. * CPL_LSB and CPL_MSB
  341. * Only one of these 2 macros should be defined and specifies the byte
  342. * ordering for the current platform.
  343. * This should be defined in the Makefile, but if it is not then
  344. * the default is CPL_LSB (Intel ordering, LSB first).
  345. *--------------------------------------------------------------------*/
  346. #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
  347. # define CPL_MSB
  348. #endif
  349. #if ! ( defined(CPL_LSB) || defined(CPL_MSB) )
  350. #define CPL_LSB
  351. #endif
  352. #if defined(CPL_LSB)
  353. # define CPL_IS_LSB 1
  354. #else
  355. # define CPL_IS_LSB 0
  356. #endif
  357. /*---------------------------------------------------------------------
  358. * Little endian <==> big endian byte swap macros.
  359. *--------------------------------------------------------------------*/
  360. #define CPL_SWAP16(x) \
  361. ((GUInt16)( \
  362. (((GUInt16)(x) & 0x00ffU) << 8) | \
  363. (((GUInt16)(x) & 0xff00U) >> 8) ))
  364. #define CPL_SWAP16PTR(x) \
  365. { \
  366. GByte byTemp, *_pabyDataT = (GByte *) (x); \
  367. \
  368. byTemp = _pabyDataT[0]; \
  369. _pabyDataT[0] = _pabyDataT[1]; \
  370. _pabyDataT[1] = byTemp; \
  371. }
  372. #define CPL_SWAP32(x) \
  373. ((GUInt32)( \
  374. (((GUInt32)(x) & (GUInt32)0x000000ffUL) << 24) | \
  375. (((GUInt32)(x) & (GUInt32)0x0000ff00UL) << 8) | \
  376. (((GUInt32)(x) & (GUInt32)0x00ff0000UL) >> 8) | \
  377. (((GUInt32)(x) & (GUInt32)0xff000000UL) >> 24) ))
  378. #define CPL_SWAP32PTR(x) \
  379. { \
  380. GByte byTemp, *_pabyDataT = (GByte *) (x); \
  381. \
  382. byTemp = _pabyDataT[0]; \
  383. _pabyDataT[0] = _pabyDataT[3]; \
  384. _pabyDataT[3] = byTemp; \
  385. byTemp = _pabyDataT[1]; \
  386. _pabyDataT[1] = _pabyDataT[2]; \
  387. _pabyDataT[2] = byTemp; \
  388. }
  389. #define CPL_SWAP64PTR(x) \
  390. { \
  391. GByte byTemp, *_pabyDataT = (GByte *) (x); \
  392. \
  393. byTemp = _pabyDataT[0]; \
  394. _pabyDataT[0] = _pabyDataT[7]; \
  395. _pabyDataT[7] = byTemp; \
  396. byTemp = _pabyDataT[1]; \
  397. _pabyDataT[1] = _pabyDataT[6]; \
  398. _pabyDataT[6] = byTemp; \
  399. byTemp = _pabyDataT[2]; \
  400. _pabyDataT[2] = _pabyDataT[5]; \
  401. _pabyDataT[5] = byTemp; \
  402. byTemp = _pabyDataT[3]; \
  403. _pabyDataT[3] = _pabyDataT[4]; \
  404. _pabyDataT[4] = byTemp; \
  405. }
  406. /* Until we have a safe 64 bits integer data type defined, we'll replace
  407. * this version of the CPL_SWAP64() macro with a less efficient one.
  408. */
  409. /*
  410. #define CPL_SWAP64(x) \
  411. ((uint64)( \
  412. (uint64)(((uint64)(x) & (uint64)0x00000000000000ffULL) << 56) | \
  413. (uint64)(((uint64)(x) & (uint64)0x000000000000ff00ULL) << 40) | \
  414. (uint64)(((uint64)(x) & (uint64)0x0000000000ff0000ULL) << 24) | \
  415. (uint64)(((uint64)(x) & (uint64)0x00000000ff000000ULL) << 8) | \
  416. (uint64)(((uint64)(x) & (uint64)0x000000ff00000000ULL) >> 8) | \
  417. (uint64)(((uint64)(x) & (uint64)0x0000ff0000000000ULL) >> 24) | \
  418. (uint64)(((uint64)(x) & (uint64)0x00ff000000000000ULL) >> 40) | \
  419. (uint64)(((uint64)(x) & (uint64)0xff00000000000000ULL) >> 56) ))
  420. */
  421. #define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
  422. #ifdef CPL_MSB
  423. # define CPL_MSBWORD16(x) (x)
  424. # define CPL_LSBWORD16(x) CPL_SWAP16(x)
  425. # define CPL_MSBWORD32(x) (x)
  426. # define CPL_LSBWORD32(x) CPL_SWAP32(x)
  427. # define CPL_MSBPTR16(x)
  428. # define CPL_LSBPTR16(x) CPL_SWAP16PTR(x)
  429. # define CPL_MSBPTR32(x)
  430. # define CPL_LSBPTR32(x) CPL_SWAP32PTR(x)
  431. # define CPL_MSBPTR64(x)
  432. # define CPL_LSBPTR64(x) CPL_SWAP64PTR(x)
  433. #else
  434. # define CPL_LSBWORD16(x) (x)
  435. # define CPL_MSBWORD16(x) CPL_SWAP16(x)
  436. # define CPL_LSBWORD32(x) (x)
  437. # define CPL_MSBWORD32(x) CPL_SWAP32(x)
  438. # define CPL_LSBPTR16(x)
  439. # define CPL_MSBPTR16(x) CPL_SWAP16PTR(x)
  440. # define CPL_LSBPTR32(x)
  441. # define CPL_MSBPTR32(x) CPL_SWAP32PTR(x)
  442. # define CPL_LSBPTR64(x)
  443. # define CPL_MSBPTR64(x) CPL_SWAP64PTR(x)
  444. #endif
  445. /** Return a Int16 from the 2 bytes ordered in LSB order at address x */
  446. #define CPL_LSBINT16PTR(x) ((*(GByte*)(x)) | (*(((GByte*)(x))+1) << 8))
  447. /** Return a Int32 from the 4 bytes ordered in LSB order at address x */
  448. #define CPL_LSBINT32PTR(x) ((*(GByte*)(x)) | (*(((GByte*)(x))+1) << 8) | \
  449. (*(((GByte*)(x))+2) << 16) | (*(((GByte*)(x))+3) << 24))
  450. /** Return a signed Int16 from the 2 bytes ordered in LSB order at address x */
  451. #define CPL_LSBSINT16PTR(x) ((GInt16) CPL_LSBINT16PTR(x))
  452. /** Return a unsigned Int16 from the 2 bytes ordered in LSB order at address x */
  453. #define CPL_LSBUINT16PTR(x) ((GUInt16)CPL_LSBINT16PTR(x))
  454. /** Return a signed Int32 from the 4 bytes ordered in LSB order at address x */
  455. #define CPL_LSBSINT32PTR(x) ((GInt32) CPL_LSBINT32PTR(x))
  456. /** Return a unsigned Int32 from the 4 bytes ordered in LSB order at address x */
  457. #define CPL_LSBUINT32PTR(x) ((GUInt32)CPL_LSBINT32PTR(x))
  458. /* Utility macro to explicitly mark intentionally unreferenced parameters. */
  459. #ifndef UNREFERENCED_PARAM
  460. # ifdef UNREFERENCED_PARAMETER /* May be defined by Windows API */
  461. # define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param)
  462. # else
  463. # define UNREFERENCED_PARAM(param) ((void)param)
  464. # endif /* UNREFERENCED_PARAMETER */
  465. #endif /* UNREFERENCED_PARAM */
  466. /***********************************************************************
  467. * Define CPL_CVSID() macro. It can be disabled during a build by
  468. * defining DISABLE_CPLID in the compiler options.
  469. *
  470. * The cvsid_aw() function is just there to prevent reports of cpl_cvsid()
  471. * being unused.
  472. */
  473. #ifndef DISABLE_CVSID
  474. #if defined(__GNUC__) && __GNUC__ >= 4
  475. # define CPL_CVSID(string) static char cpl_cvsid[] __attribute__((used)) = string;
  476. #else
  477. # define CPL_CVSID(string) static char cpl_cvsid[] = string; \
  478. static char *cvsid_aw() { return( cvsid_aw() ? ((char *) NULL) : cpl_cvsid ); }
  479. #endif
  480. #else
  481. # define CPL_CVSID(string)
  482. #endif
  483. /* Null terminated variadic */
  484. #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
  485. # define CPL_NULL_TERMINATED __attribute__((__sentinel__))
  486. #else
  487. # define CPL_NULL_TERMINATED
  488. #endif
  489. #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
  490. #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx)))
  491. #else
  492. #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx )
  493. #endif
  494. #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
  495. #define CPL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  496. #else
  497. #define CPL_WARN_UNUSED_RESULT
  498. #endif
  499. #if defined(__GNUC__) && __GNUC__ >= 4
  500. # define CPL_UNUSED __attribute((__unused__))
  501. #else
  502. /* TODO: add cases for other compilers */
  503. # define CPL_UNUSED
  504. #endif
  505. #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
  506. #define CPL_NO_RETURN __attribute__((noreturn))
  507. #else
  508. #define CPL_NO_RETURN
  509. #endif
  510. #if !defined(DOXYGEN_SKIP)
  511. #if defined(__has_extension)
  512. #if __has_extension(attribute_deprecated_with_message)
  513. /* Clang extension */
  514. #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated(x)))
  515. #else
  516. #define CPL_WARN_DEPRECATED(x)
  517. #endif
  518. #elif defined(__GNUC__)
  519. #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated))
  520. #else
  521. #define CPL_WARN_DEPRECATED(x)
  522. #endif
  523. #endif
  524. #ifdef WARN_STANDARD_PRINTF
  525. int vsnprintf(char *str, size_t size, const char* fmt, va_list args) CPL_WARN_DEPRECATED("Use CPLvsnprintf() instead");
  526. int snprintf(char *str, size_t size, const char* fmt, ...) CPL_PRINT_FUNC_FORMAT(3,4) CPL_WARN_DEPRECATED("Use CPLsnprintf() instead");
  527. int sprintf(char *str, const char* fmt, ...) CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_DEPRECATED("Use CPLsprintf() instead");
  528. #endif
  529. #endif /* ndef CPL_BASE_H_INCLUDED */