Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

395 lines
14 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  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. #define SDL_const_cast(type, expression) const_cast<type>(expression)
  88. #else
  89. #define SDL_reinterpret_cast(type, expression) ((type)(expression))
  90. #define SDL_static_cast(type, expression) ((type)(expression))
  91. #define SDL_const_cast(type, expression) ((type)(expression))
  92. #endif
  93. /* @} *//* Cast operators */
  94. /* Define a four character code as a Uint32 */
  95. #define SDL_FOURCC(A, B, C, D) \
  96. ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
  97. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
  98. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
  99. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
  100. /**
  101. * \name Basic data types
  102. */
  103. /* @{ */
  104. typedef enum
  105. {
  106. SDL_FALSE = 0,
  107. SDL_TRUE = 1
  108. } SDL_bool;
  109. /**
  110. * \brief A signed 8-bit integer type.
  111. */
  112. typedef int8_t Sint8;
  113. /**
  114. * \brief An unsigned 8-bit integer type.
  115. */
  116. typedef uint8_t Uint8;
  117. /**
  118. * \brief A signed 16-bit integer type.
  119. */
  120. typedef int16_t Sint16;
  121. /**
  122. * \brief An unsigned 16-bit integer type.
  123. */
  124. typedef uint16_t Uint16;
  125. /**
  126. * \brief A signed 32-bit integer type.
  127. */
  128. typedef int32_t Sint32;
  129. /**
  130. * \brief An unsigned 32-bit integer type.
  131. */
  132. typedef uint32_t Uint32;
  133. /**
  134. * \brief A signed 64-bit integer type.
  135. */
  136. typedef int64_t Sint64;
  137. /**
  138. * \brief An unsigned 64-bit integer type.
  139. */
  140. typedef uint64_t Uint64;
  141. /* @} *//* Basic data types */
  142. #define SDL_COMPILE_TIME_ASSERT(name, x) \
  143. typedef int SDL_dummy_ ## name[(x) * 2 - 1]
  144. /** \cond */
  145. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  146. SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
  147. SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
  148. SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
  149. SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
  150. SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
  151. SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
  152. SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
  153. SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
  154. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  155. /** \endcond */
  156. /* Check to make sure enums are the size of ints, for structure packing.
  157. For both Watcom C/C++ and Borland C/C++ the compiler option that makes
  158. enums having the size of an int must be enabled.
  159. This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
  160. */
  161. /** \cond */
  162. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  163. #if !defined(__ANDROID__)
  164. /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
  165. typedef enum
  166. {
  167. DUMMY_ENUM_VALUE
  168. } SDL_DUMMY_ENUM;
  169. SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
  170. #endif
  171. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  172. /** \endcond */
  173. #include "begin_code.h"
  174. /* Set up for C function definitions, even when using C++ */
  175. #ifdef __cplusplus
  176. extern "C" {
  177. #endif
  178. #if defined(HAVE_ALLOCA) && !defined(alloca)
  179. # if defined(HAVE_ALLOCA_H)
  180. # include <alloca.h>
  181. # elif defined(__GNUC__)
  182. # define alloca __builtin_alloca
  183. # elif defined(_MSC_VER)
  184. # include <malloc.h>
  185. # define alloca _alloca
  186. # elif defined(__WATCOMC__)
  187. # include <malloc.h>
  188. # elif defined(__BORLANDC__)
  189. # include <malloc.h>
  190. # elif defined(__DMC__)
  191. # include <stdlib.h>
  192. # elif defined(__AIX__)
  193. #pragma alloca
  194. # elif defined(__MRC__)
  195. void *alloca(unsigned);
  196. # else
  197. char *alloca();
  198. # endif
  199. #endif
  200. #ifdef HAVE_ALLOCA
  201. #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
  202. #define SDL_stack_free(data)
  203. #else
  204. #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
  205. #define SDL_stack_free(data) SDL_free(data)
  206. #endif
  207. extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
  208. extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
  209. extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
  210. extern DECLSPEC void SDLCALL SDL_free(void *mem);
  211. extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
  212. extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
  213. extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
  214. extern DECLSPEC int SDLCALL SDL_abs(int x);
  215. /* !!! FIXME: these have side effects. You probably shouldn't use them. */
  216. /* !!! FIXME: Maybe we do forceinline functions of SDL_mini, SDL_minf, etc? */
  217. #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
  218. #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
  219. extern DECLSPEC int SDLCALL SDL_isdigit(int x);
  220. extern DECLSPEC int SDLCALL SDL_isspace(int x);
  221. extern DECLSPEC int SDLCALL SDL_toupper(int x);
  222. extern DECLSPEC int SDLCALL SDL_tolower(int x);
  223. extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
  224. #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
  225. #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
  226. /* Note that memset() is a byte assignment and this is a 32-bit assignment, so they're not directly equivalent. */
  227. SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
  228. {
  229. #if defined(__GNUC__) && defined(i386)
  230. int u0, u1, u2;
  231. __asm__ __volatile__ (
  232. "cld \n\t"
  233. "rep ; stosl \n\t"
  234. : "=&D" (u0), "=&a" (u1), "=&c" (u2)
  235. : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, dwords))
  236. : "memory"
  237. );
  238. #else
  239. size_t _n = (dwords + 3) / 4;
  240. Uint32 *_p = SDL_static_cast(Uint32 *, dst);
  241. Uint32 _val = (val);
  242. if (dwords == 0)
  243. return;
  244. switch (dwords % 4)
  245. {
  246. case 0: do { *_p++ = _val;
  247. case 3: *_p++ = _val;
  248. case 2: *_p++ = _val;
  249. case 1: *_p++ = _val;
  250. } while ( --_n );
  251. }
  252. #endif
  253. }
  254. extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
  255. SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords)
  256. {
  257. return SDL_memcpy(dst, src, dwords * 4);
  258. }
  259. extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len);
  260. extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
  261. extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
  262. extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
  263. extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
  264. extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
  265. extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
  266. extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);
  267. extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
  268. extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
  269. extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
  270. extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
  271. extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
  272. extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
  273. extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
  274. extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
  275. extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
  276. extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
  277. extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
  278. extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
  279. extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
  280. extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
  281. extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
  282. extern DECLSPEC double SDLCALL SDL_atof(const char *str);
  283. extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
  284. extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
  285. extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
  286. extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
  287. extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
  288. extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
  289. extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
  290. extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
  291. extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
  292. extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
  293. extern DECLSPEC int SDLCALL SDL_vsscanf(const char *text, const char *fmt, va_list ap);
  294. extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
  295. extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
  296. #ifndef HAVE_M_PI
  297. #ifndef M_PI
  298. #define M_PI 3.14159265358979323846264338327950288 /* pi */
  299. #endif
  300. #endif
  301. extern DECLSPEC double SDLCALL SDL_acos(double x);
  302. extern DECLSPEC double SDLCALL SDL_asin(double x);
  303. extern DECLSPEC double SDLCALL SDL_atan(double x);
  304. extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
  305. extern DECLSPEC double SDLCALL SDL_ceil(double x);
  306. extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
  307. extern DECLSPEC double SDLCALL SDL_cos(double x);
  308. extern DECLSPEC float SDLCALL SDL_cosf(float x);
  309. extern DECLSPEC double SDLCALL SDL_fabs(double x);
  310. extern DECLSPEC double SDLCALL SDL_floor(double x);
  311. extern DECLSPEC double SDLCALL SDL_log(double x);
  312. extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
  313. extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
  314. extern DECLSPEC double SDLCALL SDL_sin(double x);
  315. extern DECLSPEC float SDLCALL SDL_sinf(float x);
  316. extern DECLSPEC double SDLCALL SDL_sqrt(double x);
  317. /* The SDL implementation of iconv() returns these error codes */
  318. #define SDL_ICONV_ERROR (size_t)-1
  319. #define SDL_ICONV_E2BIG (size_t)-2
  320. #define SDL_ICONV_EILSEQ (size_t)-3
  321. #define SDL_ICONV_EINVAL (size_t)-4
  322. /* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
  323. typedef struct _SDL_iconv_t *SDL_iconv_t;
  324. extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
  325. const char *fromcode);
  326. extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
  327. extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
  328. size_t * inbytesleft, char **outbuf,
  329. size_t * outbytesleft);
  330. /**
  331. * This function converts a string between encodings in one pass, returning a
  332. * string that must be freed with SDL_free() or NULL on error.
  333. */
  334. extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
  335. const char *fromcode,
  336. const char *inbuf,
  337. size_t inbytesleft);
  338. #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
  339. #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
  340. #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
  341. /* Ends C function definitions when using C++ */
  342. #ifdef __cplusplus
  343. }
  344. #endif
  345. #include "close_code.h"
  346. #endif /* _SDL_stdinc_h */
  347. /* vi: set ts=4 sw=4 expandtab: */