src/stdlib/SDL_iconv.c
changeset 2135 0313af081a84
parent 1895 c121d94672cb
child 2136 5a1b6fe6e90f
     1.1 --- a/src/stdlib/SDL_iconv.c	Wed Jun 27 10:17:35 2007 +0000
     1.2 +++ b/src/stdlib/SDL_iconv.c	Thu Jun 28 06:57:08 2007 +0000
     1.3 @@ -32,10 +32,24 @@
     1.4  
     1.5  size_t
     1.6  SDL_iconv(SDL_iconv_t cd,
     1.7 -          char **inbuf, size_t * inbytesleft,
     1.8 +          const char **inbuf, size_t * inbytesleft,
     1.9            char **outbuf, size_t * outbytesleft)
    1.10  {
    1.11 -    size_t retCode = iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft);
    1.12 +    size_t retCode;
    1.13 +#ifdef ICONV_REALLY_MODIFIES_INBUF
    1.14 +    if (inbuf && *inbuf && inbytesleft) {
    1.15 +        char *tmp = SDL_stack_alloc(char, *inbytesleft);
    1.16 +        char *ptr = tmp;
    1.17 +        SDL_memcpy(tmp, inbuf, *inbytesleft);
    1.18 +        retCode = iconv(cd, &ptr, inbytesleft, outbuf, outbytesleft);
    1.19 +        inbuf += (ptr - tmp);
    1.20 +        SDL_stack_free(tmp);
    1.21 +    } else {
    1.22 +        retCode = iconv(cd, NULL, inbytesleft, outbuf, outbytesleft);
    1.23 +    }
    1.24 +#else
    1.25 +    retCode = iconv(cd, (char **) inbuf, inbytesleft, outbuf, outbytesleft);
    1.26 +#endif
    1.27      if (retCode == (size_t) - 1) {
    1.28          switch (errno) {
    1.29          case E2BIG:
    1.30 @@ -154,13 +168,14 @@
    1.31  
    1.32  size_t
    1.33  SDL_iconv(SDL_iconv_t cd,
    1.34 -          char **inbuf, size_t * inbytesleft,
    1.35 +          const char **inbuf, size_t * inbytesleft,
    1.36            char **outbuf, size_t * outbytesleft)
    1.37  {
    1.38      /* For simplicity, we'll convert everything to and from UCS-4 */
    1.39 -    char *src, *dst;
    1.40 +    const char *src;
    1.41 +    char *dst;
    1.42      size_t srclen, dstlen;
    1.43 -    Uint32 ch;
    1.44 +    Uint32 ch = 0;
    1.45      size_t total;
    1.46  
    1.47      if (!inbuf || !*inbuf) {
    1.48 @@ -755,7 +770,7 @@
    1.49  #endif /* !HAVE_ICONV */
    1.50  
    1.51  char *
    1.52 -SDL_iconv_string(const char *tocode, const char *fromcode, char *inbuf,
    1.53 +SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
    1.54                   size_t inbytesleft)
    1.55  {
    1.56      SDL_iconv_t cd;