include/SDL_stdinc.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 05 Jul 2013 23:57:19 -0700
changeset 7351 668a3dc28361
parent 7308 728e5f22a82f
child 7382 898992405fa7
permissions -rw-r--r--
Removed the inline functions from SDL_stdinc.h
Having the SDL functions inline is causing build issues, and in the case of malloc(), etc. causing malloc/free mismatches, if the application build environment differs from the SDL build environment.

In the interest of safety and consistency, the functions will always be in the SDL library and will only be redirected to the C library there, if they are available.

See the following threads on the SDL mailing list for the gruesome details:
* SDL_stdinc.h inlines problematic when application not compiled in exact same feature environment
* Error compiling program against SDL2 with -std=c++11 g++ flag
slouken@4761
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6885
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
slouken@4761
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@4761
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@4761
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@4761
    20
*/
slouken@4761
    21
slouken@4761
    22
/**
slouken@4761
    23
 *  \file SDL_stdinc.h
slouken@7191
    24
 *
slouken@4761
    25
 *  This is a general header that includes C language support.
slouken@4761
    26
 */
slouken@4761
    27
slouken@4761
    28
#ifndef _SDL_stdinc_h
slouken@4761
    29
#define _SDL_stdinc_h
slouken@4761
    30
slouken@4761
    31
#include "SDL_config.h"
slouken@4761
    32
slouken@4761
    33
#ifdef HAVE_SYS_TYPES_H
slouken@4761
    34
#include <sys/types.h>
slouken@4761
    35
#endif
slouken@4761
    36
#ifdef HAVE_STDIO_H
slouken@4761
    37
#include <stdio.h>
slouken@4761
    38
#endif
slouken@4761
    39
#if defined(STDC_HEADERS)
slouken@4761
    40
# include <stdlib.h>
slouken@4761
    41
# include <stddef.h>
slouken@4761
    42
# include <stdarg.h>
slouken@4761
    43
#else
slouken@4761
    44
# if defined(HAVE_STDLIB_H)
slouken@4761
    45
#  include <stdlib.h>
slouken@4761
    46
# elif defined(HAVE_MALLOC_H)
slouken@4761
    47
#  include <malloc.h>
slouken@4761
    48
# endif
slouken@4761
    49
# if defined(HAVE_STDDEF_H)
slouken@4761
    50
#  include <stddef.h>
slouken@4761
    51
# endif
slouken@4761
    52
# if defined(HAVE_STDARG_H)
slouken@4761
    53
#  include <stdarg.h>
slouken@4761
    54
# endif
slouken@4761
    55
#endif
slouken@4761
    56
#ifdef HAVE_STRING_H
slouken@4761
    57
# if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
slouken@4761
    58
#  include <memory.h>
slouken@4761
    59
# endif
slouken@4761
    60
# include <string.h>
slouken@4761
    61
#endif
slouken@4761
    62
#ifdef HAVE_STRINGS_H
slouken@4761
    63
# include <strings.h>
slouken@4761
    64
#endif
slouken@4761
    65
#if defined(HAVE_INTTYPES_H)
slouken@4761
    66
# include <inttypes.h>
slouken@4761
    67
#elif defined(HAVE_STDINT_H)
slouken@4761
    68
# include <stdint.h>
slouken@4761
    69
#endif
slouken@4761
    70
#ifdef HAVE_CTYPE_H
slouken@4761
    71
# include <ctype.h>
slouken@4761
    72
#endif
slouken@4761
    73
#ifdef HAVE_MATH_H
slouken@4761
    74
# include <math.h>
slouken@4761
    75
#endif
slouken@4761
    76
#if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
slouken@4761
    77
# include <iconv.h>
slouken@4761
    78
#endif
slouken@4761
    79
slouken@4761
    80
/**
slouken@4761
    81
 *  The number of elements in an array.
slouken@4761
    82
 */
slouken@7191
    83
#define SDL_arraysize(array)    (sizeof(array)/sizeof(array[0]))
slouken@7191
    84
#define SDL_TABLESIZE(table)    SDL_arraysize(table)
slouken@4761
    85
slouken@4761
    86
/**
slouken@4761
    87
 *  \name Cast operators
slouken@7191
    88
 *
slouken@4761
    89
 *  Use proper C++ casts when compiled as C++ to be compatible with the option
slouken@4761
    90
 *  -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
slouken@4761
    91
 */
slouken@4761
    92
/*@{*/
slouken@4761
    93
#ifdef __cplusplus
slouken@4761
    94
#define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
slouken@4761
    95
#define SDL_static_cast(type, expression) static_cast<type>(expression)
icculus@7076
    96
#define SDL_const_cast(type, expression) const_cast<type>(expression)
slouken@4761
    97
#else
slouken@4761
    98
#define SDL_reinterpret_cast(type, expression) ((type)(expression))
slouken@4761
    99
#define SDL_static_cast(type, expression) ((type)(expression))
icculus@7076
   100
#define SDL_const_cast(type, expression) ((type)(expression))
slouken@4761
   101
#endif
slouken@4761
   102
/*@}*//*Cast operators*/
slouken@4761
   103
slouken@4761
   104
/* Define a four character code as a Uint32 */
slouken@4761
   105
#define SDL_FOURCC(A, B, C, D) \
slouken@4761
   106
    ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
slouken@4761
   107
     (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
slouken@4761
   108
     (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
slouken@4761
   109
     (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
slouken@4761
   110
slouken@4761
   111
/**
slouken@4761
   112
 *  \name Basic data types
slouken@4761
   113
 */
slouken@4761
   114
/*@{*/
slouken@4761
   115
slouken@4761
   116
typedef enum
slouken@4761
   117
{
slouken@4761
   118
    SDL_FALSE = 0,
slouken@4761
   119
    SDL_TRUE = 1
slouken@4761
   120
} SDL_bool;
slouken@4761
   121
slouken@4761
   122
/**
slouken@4761
   123
 * \brief A signed 8-bit integer type.
slouken@4761
   124
 */
slouken@4761
   125
typedef int8_t Sint8;
slouken@4761
   126
/**
slouken@4761
   127
 * \brief An unsigned 8-bit integer type.
slouken@4761
   128
 */
slouken@4761
   129
typedef uint8_t Uint8;
slouken@4761
   130
/**
slouken@4761
   131
 * \brief A signed 16-bit integer type.
slouken@4761
   132
 */
slouken@4761
   133
typedef int16_t Sint16;
slouken@4761
   134
/**
slouken@4761
   135
 * \brief An unsigned 16-bit integer type.
slouken@4761
   136
 */
slouken@4761
   137
typedef uint16_t Uint16;
slouken@4761
   138
/**
slouken@4761
   139
 * \brief A signed 32-bit integer type.
slouken@4761
   140
 */
slouken@4761
   141
typedef int32_t Sint32;
slouken@4761
   142
/**
slouken@4761
   143
 * \brief An unsigned 32-bit integer type.
slouken@4761
   144
 */
slouken@4761
   145
typedef uint32_t Uint32;
slouken@4761
   146
slouken@4761
   147
/**
slouken@4761
   148
 * \brief A signed 64-bit integer type.
slouken@4761
   149
 */
slouken@4761
   150
typedef int64_t Sint64;
slouken@4761
   151
/**
slouken@4761
   152
 * \brief An unsigned 64-bit integer type.
slouken@4761
   153
 */
slouken@4761
   154
typedef uint64_t Uint64;
slouken@4761
   155
slouken@4761
   156
/*@}*//*Basic data types*/
slouken@4761
   157
slouken@4761
   158
slouken@4761
   159
#define SDL_COMPILE_TIME_ASSERT(name, x)               \
slouken@4761
   160
       typedef int SDL_dummy_ ## name[(x) * 2 - 1]
slouken@4761
   161
/** \cond */
slouken@4761
   162
#ifndef DOXYGEN_SHOULD_IGNORE_THIS
slouken@4761
   163
SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
slouken@4761
   164
SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
slouken@4761
   165
SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
slouken@4761
   166
SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
slouken@4761
   167
SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
slouken@4761
   168
SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
slouken@4761
   169
SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
slouken@4761
   170
SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
slouken@4761
   171
#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
slouken@4761
   172
/** \endcond */
slouken@4761
   173
slouken@4761
   174
/* Check to make sure enums are the size of ints, for structure packing.
slouken@4761
   175
   For both Watcom C/C++ and Borland C/C++ the compiler option that makes
slouken@4761
   176
   enums having the size of an int must be enabled.
slouken@4761
   177
   This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
slouken@4761
   178
*/
slouken@4761
   179
slouken@4761
   180
/** \cond */
slouken@4761
   181
#ifndef DOXYGEN_SHOULD_IGNORE_THIS
slouken@7191
   182
#if !defined(__ANDROID__)
paul@4697
   183
   /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
slouken@4761
   184
typedef enum
slouken@4761
   185
{
slouken@4761
   186
    DUMMY_ENUM_VALUE
slouken@4761
   187
} SDL_DUMMY_ENUM;
slouken@4761
   188
slouken@4761
   189
SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
slouken@4761
   190
#endif
slouken@4761
   191
#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
slouken@4761
   192
/** \endcond */
slouken@4761
   193
slouken@4761
   194
#include "begin_code.h"
slouken@4761
   195
/* Set up for C function definitions, even when using C++ */
slouken@4761
   196
#ifdef __cplusplus
slouken@4761
   197
extern "C" {
slouken@4761
   198
#endif
slouken@4761
   199
slouken@4761
   200
#if defined(HAVE_ALLOCA) && !defined(alloca)
slouken@4761
   201
# if defined(HAVE_ALLOCA_H)
slouken@4761
   202
#  include <alloca.h>
slouken@4761
   203
# elif defined(__GNUC__)
slouken@4761
   204
#  define alloca __builtin_alloca
slouken@4761
   205
# elif defined(_MSC_VER)
slouken@4761
   206
#  include <malloc.h>
slouken@4761
   207
#  define alloca _alloca
slouken@4761
   208
# elif defined(__WATCOMC__)
slouken@4761
   209
#  include <malloc.h>
slouken@4761
   210
# elif defined(__BORLANDC__)
slouken@4761
   211
#  include <malloc.h>
slouken@4761
   212
# elif defined(__DMC__)
slouken@4761
   213
#  include <stdlib.h>
slouken@4761
   214
# elif defined(__AIX__)
slouken@4761
   215
#pragma alloca
slouken@4761
   216
# elif defined(__MRC__)
slouken@4761
   217
void *alloca(unsigned);
slouken@4761
   218
# else
slouken@4761
   219
char *alloca();
slouken@4761
   220
# endif
slouken@4761
   221
#endif
slouken@4761
   222
#ifdef HAVE_ALLOCA
slouken@4761
   223
#define SDL_stack_alloc(type, count)    (type*)alloca(sizeof(type)*(count))
slouken@4761
   224
#define SDL_stack_free(data)
slouken@4761
   225
#else
slouken@4761
   226
#define SDL_stack_alloc(type, count)    (type*)SDL_malloc(sizeof(type)*(count))
slouken@4761
   227
#define SDL_stack_free(data)            SDL_free(data)
slouken@4761
   228
#endif
slouken@4761
   229
icculus@7003
   230
extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
icculus@7003
   231
extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
icculus@7003
   232
extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
icculus@7003
   233
extern DECLSPEC void SDLCALL SDL_free(void *mem);
slouken@4761
   234
icculus@7003
   235
extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
icculus@7003
   236
extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
slouken@4761
   237
icculus@7003
   238
extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
slouken@4761
   239
icculus@7003
   240
extern DECLSPEC int SDLCALL SDL_abs(int x);
icculus@7003
   241
icculus@7003
   242
/* !!! FIXME: these have side effects. You probably shouldn't use them. */
icculus@7003
   243
/* !!! FIXME: Maybe we do forceinline functions of SDL_mini, SDL_minf, etc? */
icculus@7003
   244
#define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
icculus@7003
   245
#define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
icculus@7003
   246
icculus@7003
   247
extern DECLSPEC int SDLCALL SDL_isdigit(int x);
icculus@7003
   248
extern DECLSPEC int SDLCALL SDL_isspace(int x);
icculus@7003
   249
extern DECLSPEC int SDLCALL SDL_toupper(int x);
icculus@7003
   250
extern DECLSPEC int SDLCALL SDL_tolower(int x);
icculus@7003
   251
icculus@7003
   252
extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
slouken@4761
   253
icculus@7003
   254
#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
icculus@7003
   255
#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
icculus@7003
   256
slouken@7351
   257
/* Note that the semantics are different from memset() in that this is a 32-bit assignment */
slouken@7351
   258
SDL_FORCE_INLINE void SDL_memset4(void *dst, int val, size_t dwords)
icculus@7003
   259
{
icculus@7003
   260
#if defined(__GNUC__) && defined(i386)
icculus@7003
   261
    int u0, u1, u2;
icculus@7003
   262
    __asm__ __volatile__ (
icculus@7003
   263
        "cld \n\t"
icculus@7003
   264
        "rep ; stosl \n\t"
icculus@7003
   265
        : "=&D" (u0), "=&a" (u1), "=&c" (u2)
slouken@7351
   266
        : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, dwords))
icculus@7003
   267
        : "memory"
icculus@7003
   268
    );
slouken@4761
   269
#else
slouken@7351
   270
    size_t _n = (dwords + 3) / 4;
icculus@7003
   271
    Uint32 *_p = SDL_static_cast(Uint32 *, dst);
icculus@7003
   272
    Uint32 _val = (val);
slouken@7351
   273
    if (dwords == 0)
icculus@7003
   274
        return;
slouken@7351
   275
    switch (dwords % 4)
icculus@7003
   276
    {
icculus@7003
   277
        case 0: do {    *_p++ = _val;
icculus@7003
   278
        case 3:         *_p++ = _val;
icculus@7003
   279
        case 2:         *_p++ = _val;
icculus@7003
   280
        case 1:         *_p++ = _val;
icculus@7003
   281
        } while ( --_n );
icculus@7003
   282
    }
icculus@7003
   283
#endif
icculus@7003
   284
}
icculus@7003
   285
icculus@7003
   286
icculus@7003
   287
extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
icculus@7003
   288
icculus@7003
   289
SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords)
icculus@7003
   290
{
icculus@7003
   291
    return SDL_memcpy(dst, src, dwords * 4);
icculus@7003
   292
}
icculus@7003
   293
icculus@7003
   294
extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len);
slouken@7351
   295
extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
slouken@4761
   296
slouken@7351
   297
extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
slouken@7351
   298
extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
slouken@7351
   299
extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
slouken@4761
   300
icculus@7003
   301
extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
icculus@7003
   302
extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
icculus@7003
   303
extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);
icculus@7003
   304
extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
icculus@7003
   305
extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
icculus@7003
   306
extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
icculus@7003
   307
extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
icculus@7003
   308
extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
icculus@7003
   309
extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
icculus@7003
   310
extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
icculus@7003
   311
extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
slouken@4761
   312
icculus@7003
   313
extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
slouken@7351
   314
extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
slouken@7351
   315
extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
icculus@7003
   316
extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
icculus@7003
   317
extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
icculus@7003
   318
extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
slouken@4761
   319
icculus@7003
   320
extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
icculus@7003
   321
extern DECLSPEC double SDLCALL SDL_atof(const char *str);
slouken@7351
   322
extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
slouken@7351
   323
extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
slouken@7351
   324
extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
slouken@7351
   325
extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
slouken@7351
   326
extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
icculus@7003
   327
icculus@7003
   328
extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
slouken@7351
   329
extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
slouken@7351
   330
extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
slouken@7351
   331
extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
slouken@4761
   332
icculus@7003
   333
extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
icculus@7003
   334
extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
icculus@7003
   335
extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
slouken@4761
   336
slouken@4761
   337
#ifndef HAVE_M_PI
slouken@6627
   338
#ifndef M_PI
slouken@4761
   339
#define M_PI    3.14159265358979323846264338327950288   /* pi */
slouken@4761
   340
#endif
slouken@6627
   341
#endif
slouken@4761
   342
icculus@7003
   343
extern DECLSPEC double SDLCALL SDL_atan(double x);
icculus@7003
   344
extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
icculus@7003
   345
extern DECLSPEC double SDLCALL SDL_ceil(double x);
icculus@7003
   346
extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
icculus@7003
   347
extern DECLSPEC double SDLCALL SDL_cos(double x);
icculus@7003
   348
extern DECLSPEC float SDLCALL SDL_cosf(float x);
icculus@7003
   349
extern DECLSPEC double SDLCALL SDL_fabs(double x);
icculus@7003
   350
extern DECLSPEC double SDLCALL SDL_floor(double x);
icculus@7003
   351
extern DECLSPEC double SDLCALL SDL_log(double x);
icculus@7003
   352
extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
icculus@7003
   353
extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
icculus@7003
   354
extern DECLSPEC double SDLCALL SDL_sin(double x);
icculus@7003
   355
extern DECLSPEC float SDLCALL SDL_sinf(float x);
icculus@7003
   356
extern DECLSPEC double SDLCALL SDL_sqrt(double x);
slouken@4761
   357
slouken@4761
   358
/* The SDL implementation of iconv() returns these error codes */
slouken@7191
   359
#define SDL_ICONV_ERROR     (size_t)-1
slouken@7191
   360
#define SDL_ICONV_E2BIG     (size_t)-2
slouken@7191
   361
#define SDL_ICONV_EILSEQ    (size_t)-3
slouken@7191
   362
#define SDL_ICONV_EINVAL    (size_t)-4
slouken@4761
   363
icculus@7003
   364
/* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
slouken@4761
   365
typedef struct _SDL_iconv_t *SDL_iconv_t;
slouken@4761
   366
extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
slouken@4761
   367
                                                   const char *fromcode);
slouken@4761
   368
extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
slouken@4761
   369
extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
slouken@4761
   370
                                         size_t * inbytesleft, char **outbuf,
slouken@4761
   371
                                         size_t * outbytesleft);
slouken@4761
   372
/**
slouken@4761
   373
 *  This function converts a string between encodings in one pass, returning a
slouken@4761
   374
 *  string that must be freed with SDL_free() or NULL on error.
slouken@4761
   375
 */
slouken@4761
   376
extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
slouken@4761
   377
                                               const char *fromcode,
slouken@4761
   378
                                               const char *inbuf,
slouken@4761
   379
                                               size_t inbytesleft);
slouken@7191
   380
#define SDL_iconv_utf8_locale(S)    SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
slouken@7191
   381
#define SDL_iconv_utf8_ucs2(S)      (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
slouken@7191
   382
#define SDL_iconv_utf8_ucs4(S)      (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
slouken@4761
   383
slouken@4761
   384
/* Ends C function definitions when using C++ */
slouken@4761
   385
#ifdef __cplusplus
slouken@4761
   386
}
slouken@4761
   387
#endif
slouken@4761
   388
#include "close_code.h"
slouken@4761
   389
slouken@4761
   390
#endif /* _SDL_stdinc_h */
slouken@4761
   391
slouken@4761
   392
/* vi: set ts=4 sw=4 expandtab: */