SDL_stdinc.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. /*
  2. SDL - Simple DirectMedia Layer
  3. Copyright (C) 1997-2010 Sam Lantinga
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. Sam Lantinga
  16. [email protected]
  17. */
  18. /**
  19. * \file SDL_stdinc.h
  20. *
  21. * This is a general header that includes C language support.
  22. */
  23. #ifndef _SDL_stdinc_h
  24. #define _SDL_stdinc_h
  25. #include "SDL_config.h"
  26. #ifdef HAVE_SYS_TYPES_H
  27. #include <sys/types.h>
  28. #endif
  29. #ifdef HAVE_STDIO_H
  30. #include <stdio.h>
  31. #endif
  32. #if defined(STDC_HEADERS)
  33. # include <stdlib.h>
  34. # include <stddef.h>
  35. # include <stdarg.h>
  36. #else
  37. # if defined(HAVE_STDLIB_H)
  38. # include <stdlib.h>
  39. # elif defined(HAVE_MALLOC_H)
  40. # include <malloc.h>
  41. # endif
  42. # if defined(HAVE_STDDEF_H)
  43. # include <stddef.h>
  44. # endif
  45. # if defined(HAVE_STDARG_H)
  46. # include <stdarg.h>
  47. # endif
  48. #endif
  49. #ifdef HAVE_STRING_H
  50. # if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
  51. # include <memory.h>
  52. # endif
  53. # include <string.h>
  54. #endif
  55. #ifdef HAVE_STRINGS_H
  56. # include <strings.h>
  57. #endif
  58. #if defined(HAVE_INTTYPES_H)
  59. # include <inttypes.h>
  60. #elif defined(HAVE_STDINT_H)
  61. # include <stdint.h>
  62. #endif
  63. #ifdef HAVE_CTYPE_H
  64. # include <ctype.h>
  65. #endif
  66. #ifdef HAVE_MATH_H
  67. # include <math.h>
  68. #endif
  69. #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
  70. # include <iconv.h>
  71. #endif
  72. /**
  73. * The number of elements in an array.
  74. */
  75. #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
  76. #define SDL_TABLESIZE(table) SDL_arraysize(table)
  77. /**
  78. * \name Cast operators
  79. *
  80. * Use proper C++ casts when compiled as C++ to be compatible with the option
  81. * -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
  82. */
  83. /*@{*/
  84. #ifdef __cplusplus
  85. #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
  86. #define SDL_static_cast(type, expression) static_cast<type>(expression)
  87. #else
  88. #define SDL_reinterpret_cast(type, expression) ((type)(expression))
  89. #define SDL_static_cast(type, expression) ((type)(expression))
  90. #endif
  91. /*@}*//*Cast operators*/
  92. /* Define a four character code as a Uint32 */
  93. #define SDL_FOURCC(A, B, C, D) \
  94. ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
  95. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
  96. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
  97. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
  98. /**
  99. * \name Basic data types
  100. */
  101. /*@{*/
  102. typedef enum
  103. {
  104. SDL_FALSE = 0,
  105. SDL_TRUE = 1
  106. } SDL_bool;
  107. /**
  108. * \brief A signed 8-bit integer type.
  109. */
  110. typedef int8_t Sint8;
  111. /**
  112. * \brief An unsigned 8-bit integer type.
  113. */
  114. typedef uint8_t Uint8;
  115. /**
  116. * \brief A signed 16-bit integer type.
  117. */
  118. typedef int16_t Sint16;
  119. /**
  120. * \brief An unsigned 16-bit integer type.
  121. */
  122. typedef uint16_t Uint16;
  123. /**
  124. * \brief A signed 32-bit integer type.
  125. */
  126. typedef int32_t Sint32;
  127. /**
  128. * \brief An unsigned 32-bit integer type.
  129. */
  130. typedef uint32_t Uint32;
  131. #ifdef SDL_HAS_64BIT_TYPE
  132. /**
  133. * \brief A signed 64-bit integer type.
  134. * \warning On platforms without any sort of 64-bit datatype, this is equivalent to Sint32!
  135. */
  136. typedef int64_t Sint64;
  137. /**
  138. * \brief An unsigned 64-bit integer type.
  139. * \warning On platforms without any sort of 64-bit datatype, this is equivalent to Uint32!
  140. */
  141. typedef uint64_t Uint64;
  142. #else
  143. /* This is really just a hack to prevent the compiler from complaining */
  144. typedef Sint32 Sint64;
  145. typedef Uint32 Uint64;
  146. #endif
  147. /*@}*//*Basic data types*/
  148. #define SDL_COMPILE_TIME_ASSERT(name, x) \
  149. typedef int SDL_dummy_ ## name[(x) * 2 - 1]
  150. /** \cond */
  151. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  152. SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
  153. SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
  154. SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
  155. SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
  156. SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
  157. SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
  158. #if !defined(__NINTENDODS__) && !defined(__ANDROID__)
  159. /* TODO: figure out why the following happens:
  160. include/SDL_stdinc.h:150: error: size of array 'SDL_dummy_uint64' is negative
  161. include/SDL_stdinc.h:151: error: size of array 'SDL_dummy_sint64' is negative */
  162. SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
  163. SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
  164. #endif
  165. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  166. /** \endcond */
  167. /* Check to make sure enums are the size of ints, for structure packing.
  168. For both Watcom C/C++ and Borland C/C++ the compiler option that makes
  169. enums having the size of an int must be enabled.
  170. This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
  171. */
  172. /* Enable enums always int in CodeWarrior (for MPW use "-enum int") */
  173. #ifdef __MWERKS__
  174. #pragma enumsalwaysint on
  175. #endif
  176. /** \cond */
  177. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  178. #if !defined(__NINTENDODS__) && !defined(__ANDROID__)
  179. /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
  180. typedef enum
  181. {
  182. DUMMY_ENUM_VALUE
  183. } SDL_DUMMY_ENUM;
  184. SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
  185. #endif
  186. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  187. /** \endcond */
  188. #include "begin_code.h"
  189. /* Set up for C function definitions, even when using C++ */
  190. #ifdef __cplusplus
  191. /* *INDENT-OFF* */
  192. extern "C" {
  193. /* *INDENT-ON* */
  194. #endif
  195. #ifdef HAVE_MALLOC
  196. #define SDL_malloc malloc
  197. #else
  198. extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
  199. #endif
  200. #ifdef HAVE_CALLOC
  201. #define SDL_calloc calloc
  202. #else
  203. extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
  204. #endif
  205. #ifdef HAVE_REALLOC
  206. #define SDL_realloc realloc
  207. #else
  208. extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
  209. #endif
  210. #ifdef HAVE_FREE
  211. #define SDL_free free
  212. #else
  213. extern DECLSPEC void SDLCALL SDL_free(void *mem);
  214. #endif
  215. #if defined(HAVE_ALLOCA) && !defined(alloca)
  216. # if defined(HAVE_ALLOCA_H)
  217. # include <alloca.h>
  218. # elif defined(__GNUC__)
  219. # define alloca __builtin_alloca
  220. # elif defined(_MSC_VER)
  221. # include <malloc.h>
  222. # define alloca _alloca
  223. # elif defined(__WATCOMC__)
  224. # include <malloc.h>
  225. # elif defined(__BORLANDC__)
  226. # include <malloc.h>
  227. # elif defined(__DMC__)
  228. # include <stdlib.h>
  229. # elif defined(__AIX__)
  230. #pragma alloca
  231. # elif defined(__MRC__)
  232. void *alloca(unsigned);
  233. # else
  234. char *alloca();
  235. # endif
  236. #endif
  237. #ifdef HAVE_ALLOCA
  238. #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
  239. #define SDL_stack_free(data)
  240. #else
  241. #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
  242. #define SDL_stack_free(data) SDL_free(data)
  243. #endif
  244. #ifdef HAVE_GETENV
  245. #define SDL_getenv getenv
  246. #else
  247. extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
  248. #endif
  249. /* SDL_putenv() has moved to SDL_compat. */
  250. #ifdef HAVE_SETENV
  251. #define SDL_setenv setenv
  252. #else
  253. extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value,
  254. int overwrite);
  255. #endif
  256. #ifdef HAVE_QSORT
  257. #define SDL_qsort qsort
  258. #else
  259. extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size,
  260. int (*compare) (const void *,
  261. const void *));
  262. #endif
  263. #ifdef HAVE_ABS
  264. #define SDL_abs abs
  265. #else
  266. #define SDL_abs(X) ((X) < 0 ? -(X) : (X))
  267. #endif
  268. #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
  269. #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
  270. #ifdef HAVE_CTYPE_H
  271. #define SDL_isdigit(X) isdigit(X)
  272. #define SDL_isspace(X) isspace(X)
  273. #define SDL_toupper(X) toupper(X)
  274. #define SDL_tolower(X) tolower(X)
  275. #else
  276. #define SDL_isdigit(X) (((X) >= '0') && ((X) <= '9'))
  277. #define SDL_isspace(X) (((X) == ' ') || ((X) == '\t') || ((X) == '\r') || ((X) == '\n'))
  278. #define SDL_toupper(X) (((X) >= 'a') && ((X) <= 'z') ? ('A'+((X)-'a')) : (X))
  279. #define SDL_tolower(X) (((X) >= 'A') && ((X) <= 'Z') ? ('a'+((X)-'A')) : (X))
  280. #endif
  281. #ifdef HAVE_MEMSET
  282. #define SDL_memset memset
  283. #else
  284. extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
  285. #endif
  286. #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
  287. #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
  288. #if defined(__GNUC__) && defined(i386)
  289. #define SDL_memset4(dst, val, len) \
  290. do { \
  291. int u0, u1, u2; \
  292. __asm__ __volatile__ ( \
  293. "cld\n\t" \
  294. "rep ; stosl\n\t" \
  295. : "=&D" (u0), "=&a" (u1), "=&c" (u2) \
  296. : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len)) \
  297. : "memory" ); \
  298. } while(0)
  299. #endif
  300. #ifndef SDL_memset4
  301. #define SDL_memset4(dst, val, len) \
  302. do { \
  303. unsigned _count = (len); \
  304. unsigned _n = (_count + 3) / 4; \
  305. Uint32 *_p = SDL_static_cast(Uint32 *, dst); \
  306. Uint32 _val = (val); \
  307. if (len == 0) break; \
  308. switch (_count % 4) { \
  309. case 0: do { *_p++ = _val; \
  310. case 3: *_p++ = _val; \
  311. case 2: *_p++ = _val; \
  312. case 1: *_p++ = _val; \
  313. } while ( --_n ); \
  314. } \
  315. } while(0)
  316. #endif
  317. /* We can count on memcpy existing on Mac OS X and being well-tuned. */
  318. #if defined(__MACH__) && defined(__APPLE__)
  319. #define SDL_memcpy(dst, src, len) memcpy(dst, src, len)
  320. #elif defined(__GNUC__) && defined(i386)
  321. #define SDL_memcpy(dst, src, len) \
  322. do { \
  323. int u0, u1, u2; \
  324. __asm__ __volatile__ ( \
  325. "cld\n\t" \
  326. "rep ; movsl\n\t" \
  327. "testb $2,%b4\n\t" \
  328. "je 1f\n\t" \
  329. "movsw\n" \
  330. "1:\ttestb $1,%b4\n\t" \
  331. "je 2f\n\t" \
  332. "movsb\n" \
  333. "2:" \
  334. : "=&c" (u0), "=&D" (u1), "=&S" (u2) \
  335. : "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst),"2" (src) \
  336. : "memory" ); \
  337. } while(0)
  338. #endif
  339. #ifndef SDL_memcpy
  340. #ifdef HAVE_MEMCPY
  341. #define SDL_memcpy memcpy
  342. #elif defined(HAVE_BCOPY)
  343. #define SDL_memcpy(d, s, n) bcopy((s), (d), (n))
  344. #else
  345. extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src,
  346. size_t len);
  347. #endif
  348. #endif
  349. /* We can count on memcpy existing on Mac OS X and being well-tuned. */
  350. #if defined(__MACH__) && defined(__APPLE__)
  351. #define SDL_memcpy4(dst, src, len) memcpy(dst, src, (len)*4)
  352. #elif defined(__GNUC__) && defined(i386)
  353. #define SDL_memcpy4(dst, src, len) \
  354. do { \
  355. int ecx, edi, esi; \
  356. __asm__ __volatile__ ( \
  357. "cld\n\t" \
  358. "rep ; movsl" \
  359. : "=&c" (ecx), "=&D" (edi), "=&S" (esi) \
  360. : "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src) \
  361. : "memory" ); \
  362. } while(0)
  363. #endif
  364. #ifndef SDL_memcpy4
  365. #define SDL_memcpy4(dst, src, len) SDL_memcpy(dst, src, (len) << 2)
  366. #endif
  367. #if defined(__GNUC__) && defined(i386)
  368. #define SDL_revcpy(dst, src, len) \
  369. do { \
  370. int u0, u1, u2; \
  371. char *dstp = SDL_static_cast(char *, dst); \
  372. char *srcp = SDL_static_cast(char *, src); \
  373. int n = (len); \
  374. if ( n >= 4 ) { \
  375. __asm__ __volatile__ ( \
  376. "std\n\t" \
  377. "rep ; movsl\n\t" \
  378. "cld\n\t" \
  379. : "=&c" (u0), "=&D" (u1), "=&S" (u2) \
  380. : "0" (n >> 2), \
  381. "1" (dstp+(n-4)), "2" (srcp+(n-4)) \
  382. : "memory" ); \
  383. } \
  384. switch (n & 3) { \
  385. case 3: dstp[2] = srcp[2]; \
  386. case 2: dstp[1] = srcp[1]; \
  387. case 1: dstp[0] = srcp[0]; \
  388. break; \
  389. default: \
  390. break; \
  391. } \
  392. } while(0)
  393. #endif
  394. #ifndef SDL_revcpy
  395. extern DECLSPEC void *SDLCALL SDL_revcpy(void *dst, const void *src,
  396. size_t len);
  397. #endif
  398. #ifdef HAVE_MEMMOVE
  399. #define SDL_memmove memmove
  400. #elif defined(HAVE_BCOPY)
  401. #define SDL_memmove(d, s, n) bcopy((s), (d), (n))
  402. #else
  403. #define SDL_memmove(dst, src, len) \
  404. do { \
  405. if ( dst < src ) { \
  406. SDL_memcpy(dst, src, len); \
  407. } else { \
  408. SDL_revcpy(dst, src, len); \
  409. } \
  410. } while(0)
  411. #endif
  412. #ifdef HAVE_MEMCMP
  413. #define SDL_memcmp memcmp
  414. #else
  415. extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2,
  416. size_t len);
  417. #endif
  418. #ifdef HAVE_STRLEN
  419. #define SDL_strlen strlen
  420. #else
  421. extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
  422. #endif
  423. #ifdef HAVE_WCSLEN
  424. #define SDL_wcslen wcslen
  425. #else
  426. #if !defined(wchar_t) && defined(__NINTENDODS__)
  427. #define wchar_t short /* TODO: figure out why libnds doesn't have this */
  428. #endif
  429. extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t * string);
  430. #endif
  431. #ifdef HAVE_WCSLCPY
  432. #define SDL_wcslcpy wcslcpy
  433. #else
  434. extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
  435. #endif
  436. #ifdef HAVE_WCSLCAT
  437. #define SDL_wcslcat wcslcat
  438. #else
  439. extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
  440. #endif
  441. #ifdef HAVE_STRLCPY
  442. #define SDL_strlcpy strlcpy
  443. #else
  444. extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src,
  445. size_t maxlen);
  446. #endif
  447. extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src,
  448. size_t dst_bytes);
  449. #ifdef HAVE_STRLCAT
  450. #define SDL_strlcat strlcat
  451. #else
  452. extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src,
  453. size_t maxlen);
  454. #endif
  455. #ifdef HAVE_STRDUP
  456. #define SDL_strdup strdup
  457. #else
  458. extern DECLSPEC char *SDLCALL SDL_strdup(const char *string);
  459. #endif
  460. #ifdef HAVE__STRREV
  461. #define SDL_strrev _strrev
  462. #else
  463. extern DECLSPEC char *SDLCALL SDL_strrev(char *string);
  464. #endif
  465. #ifdef HAVE__STRUPR
  466. #define SDL_strupr _strupr
  467. #else
  468. extern DECLSPEC char *SDLCALL SDL_strupr(char *string);
  469. #endif
  470. #ifdef HAVE__STRLWR
  471. #define SDL_strlwr _strlwr
  472. #else
  473. extern DECLSPEC char *SDLCALL SDL_strlwr(char *string);
  474. #endif
  475. #ifdef HAVE_STRCHR
  476. #define SDL_strchr strchr
  477. #elif defined(HAVE_INDEX)
  478. #define SDL_strchr index
  479. #else
  480. extern DECLSPEC char *SDLCALL SDL_strchr(const char *string, int c);
  481. #endif
  482. #ifdef HAVE_STRRCHR
  483. #define SDL_strrchr strrchr
  484. #elif defined(HAVE_RINDEX)
  485. #define SDL_strrchr rindex
  486. #else
  487. extern DECLSPEC char *SDLCALL SDL_strrchr(const char *string, int c);
  488. #endif
  489. #ifdef HAVE_STRSTR
  490. #define SDL_strstr strstr
  491. #else
  492. extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack,
  493. const char *needle);
  494. #endif
  495. #ifdef HAVE_ITOA
  496. #define SDL_itoa itoa
  497. #else
  498. #define SDL_itoa(value, string, radix) SDL_ltoa((long)value, string, radix)
  499. #endif
  500. #ifdef HAVE__LTOA
  501. #define SDL_ltoa _ltoa
  502. #else
  503. extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *string, int radix);
  504. #endif
  505. #ifdef HAVE__UITOA
  506. #define SDL_uitoa _uitoa
  507. #else
  508. #define SDL_uitoa(value, string, radix) SDL_ultoa((long)value, string, radix)
  509. #endif
  510. #ifdef HAVE__ULTOA
  511. #define SDL_ultoa _ultoa
  512. #else
  513. extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *string,
  514. int radix);
  515. #endif
  516. #ifdef HAVE_STRTOL
  517. #define SDL_strtol strtol
  518. #else
  519. extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp,
  520. int base);
  521. #endif
  522. #ifdef HAVE_STRTOUL
  523. #define SDL_strtoul strtoul
  524. #else
  525. extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string,
  526. char **endp, int base);
  527. #endif
  528. #ifdef SDL_HAS_64BIT_TYPE
  529. #ifdef HAVE__I64TOA
  530. #define SDL_lltoa _i64toa
  531. #else
  532. extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *string,
  533. int radix);
  534. #endif
  535. #ifdef HAVE__UI64TOA
  536. #define SDL_ulltoa _ui64toa
  537. #else
  538. extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *string,
  539. int radix);
  540. #endif
  541. #ifdef HAVE_STRTOLL
  542. #define SDL_strtoll strtoll
  543. #else
  544. extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp,
  545. int base);
  546. #endif
  547. #ifdef HAVE_STRTOULL
  548. #define SDL_strtoull strtoull
  549. #else
  550. extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp,
  551. int base);
  552. #endif
  553. #endif /* SDL_HAS_64BIT_TYPE */
  554. #ifdef HAVE_STRTOD
  555. #define SDL_strtod strtod
  556. #else
  557. extern DECLSPEC double SDLCALL SDL_strtod(const char *string, char **endp);
  558. #endif
  559. #ifdef HAVE_ATOI
  560. #define SDL_atoi atoi
  561. #else
  562. #define SDL_atoi(X) SDL_strtol(X, NULL, 0)
  563. #endif
  564. #ifdef HAVE_ATOF
  565. #define SDL_atof atof
  566. #else
  567. #define SDL_atof(X) SDL_strtod(X, NULL)
  568. #endif
  569. #ifdef HAVE_STRCMP
  570. #define SDL_strcmp strcmp
  571. #else
  572. extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
  573. #endif
  574. #ifdef HAVE_STRNCMP
  575. #define SDL_strncmp strncmp
  576. #else
  577. extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2,
  578. size_t maxlen);
  579. #endif
  580. #ifdef HAVE_STRCASECMP
  581. #define SDL_strcasecmp strcasecmp
  582. #elif defined(HAVE__STRICMP)
  583. #define SDL_strcasecmp _stricmp
  584. #else
  585. extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1,
  586. const char *str2);
  587. #endif
  588. #ifdef HAVE_STRNCASECMP
  589. #define SDL_strncasecmp strncasecmp
  590. #elif defined(HAVE__STRNICMP)
  591. #define SDL_strncasecmp _strnicmp
  592. #else
  593. extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1,
  594. const char *str2, size_t maxlen);
  595. #endif
  596. #ifdef HAVE_SSCANF
  597. #define SDL_sscanf sscanf
  598. #else
  599. extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt,
  600. ...);
  601. #endif
  602. #ifdef HAVE_SNPRINTF
  603. #define SDL_snprintf snprintf
  604. #else
  605. extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen,
  606. const char *fmt, ...);
  607. #endif
  608. #ifdef HAVE_VSNPRINTF
  609. #define SDL_vsnprintf vsnprintf
  610. #else
  611. extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen,
  612. const char *fmt, va_list ap);
  613. #endif
  614. #ifndef HAVE_M_PI
  615. #define M_PI 3.14159265358979323846264338327950288 /* pi */
  616. #endif
  617. #ifdef HAVE_ATAN
  618. #define SDL_atan atan
  619. #else
  620. extern DECLSPEC double SDLCALL SDL_atan(double x);
  621. #endif
  622. #ifdef HAVE_ATAN2
  623. #define SDL_atan2 atan2
  624. #else
  625. extern DECLSPEC double SDLCALL SDL_atan2(double y, double x);
  626. #endif
  627. #ifdef HAVE_CEIL
  628. #define SDL_ceil ceil
  629. #else
  630. #define SDL_ceil(x) ((double)(int)((x)+0.5))
  631. #endif
  632. #ifdef HAVE_COPYSIGN
  633. #define SDL_copysign copysign
  634. #else
  635. extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
  636. #endif
  637. #ifdef HAVE_COS
  638. #define SDL_cos cos
  639. #else
  640. extern DECLSPEC double SDLCALL SDL_cos(double x);
  641. #endif
  642. #ifdef HAVE_COSF
  643. #define SDL_cosf cosf
  644. #else
  645. #define SDL_cosf(x) (float)SDL_cos((double)x)
  646. #endif
  647. #ifdef HAVE_FABS
  648. #define SDL_fabs fabs
  649. #else
  650. extern DECLSPEC double SDLCALL SDL_fabs(double x);
  651. #endif
  652. #ifdef HAVE_FLOOR
  653. #define SDL_floor floor
  654. #else
  655. extern DECLSPEC double SDLCALL SDL_floor(double x);
  656. #endif
  657. #ifdef HAVE_LOG
  658. #define SDL_log log
  659. #else
  660. extern DECLSPEC double SDLCALL SDL_log(double x);
  661. #endif
  662. #ifdef HAVE_POW
  663. #define SDL_pow pow
  664. #else
  665. extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
  666. #endif
  667. #ifdef HAVE_SCALBN
  668. #define SDL_scalbn scalbn
  669. #else
  670. extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
  671. #endif
  672. #ifdef HAVE_SIN
  673. #define SDL_sin sin
  674. #else
  675. extern DECLSPEC double SDLCALL SDL_sin(double x);
  676. #endif
  677. #ifdef HAVE_SINF
  678. #define SDL_sinf sinf
  679. #else
  680. #define SDL_sinf(x) (float)SDL_sin((double)x)
  681. #endif
  682. #ifdef HAVE_SQRT
  683. #define SDL_sqrt sqrt
  684. #else
  685. extern DECLSPEC double SDLCALL SDL_sqrt(double x);
  686. #endif
  687. /* The SDL implementation of iconv() returns these error codes */
  688. #define SDL_ICONV_ERROR (size_t)-1
  689. #define SDL_ICONV_E2BIG (size_t)-2
  690. #define SDL_ICONV_EILSEQ (size_t)-3
  691. #define SDL_ICONV_EINVAL (size_t)-4
  692. #if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
  693. #define SDL_iconv_t iconv_t
  694. #define SDL_iconv_open iconv_open
  695. #define SDL_iconv_close iconv_close
  696. #else
  697. typedef struct _SDL_iconv_t *SDL_iconv_t;
  698. extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
  699. const char *fromcode);
  700. extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
  701. #endif
  702. extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
  703. size_t * inbytesleft, char **outbuf,
  704. size_t * outbytesleft);
  705. /**
  706. * This function converts a string between encodings in one pass, returning a
  707. * string that must be freed with SDL_free() or NULL on error.
  708. */
  709. extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
  710. const char *fromcode,
  711. const char *inbuf,
  712. size_t inbytesleft);
  713. #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
  714. #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
  715. #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
  716. /* Ends C function definitions when using C++ */
  717. #ifdef __cplusplus
  718. /* *INDENT-OFF* */
  719. }
  720. /* *INDENT-ON* */
  721. #endif
  722. #include "close_code.h"
  723. #endif /* _SDL_stdinc_h */
  724. /* vi: set ts=4 sw=4 expandtab: */