| | |
| | | /* |
| | | Simple DirectMedia Layer |
| | | Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> |
| | | Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> |
| | | |
| | | This software is provided 'as-is', without any express or implied |
| | | warranty. In no event will the authors be held liable for any damages |
| | |
| | | iconv() may or may not use const char ** for the inbuf param. |
| | | If we get this wrong, it's just a warning, so no big deal. |
| | | */ |
| | | #if defined(_XGP6) || defined(__APPLE__) || \ |
| | | #if defined(_XGP6) || defined(__APPLE__) || defined(__RISCOS__) || \ |
| | | defined(__EMSCRIPTEN__) || \ |
| | | (defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) || \ |
| | | (defined(_NEWLIB_VERSION))) |
| | |
| | | } |
| | | |
| | | stringsize = inbytesleft > 4 ? inbytesleft : 4; |
| | | string = SDL_malloc(stringsize); |
| | | string = (char *) SDL_malloc(stringsize); |
| | | if (!string) { |
| | | SDL_iconv_close(cd); |
| | | return NULL; |
| | |
| | | SDL_memset(outbuf, 0, 4); |
| | | |
| | | while (inbytesleft > 0) { |
| | | const size_t oldinbytesleft = inbytesleft; |
| | | retCode = SDL_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); |
| | | switch (retCode) { |
| | | case SDL_ICONV_E2BIG: |
| | | { |
| | | char *oldstring = string; |
| | | stringsize *= 2; |
| | | string = SDL_realloc(string, stringsize); |
| | | string = (char *) SDL_realloc(string, stringsize); |
| | | if (!string) { |
| | | SDL_iconv_close(cd); |
| | | return NULL; |
| | |
| | | inbytesleft = 0; |
| | | break; |
| | | } |
| | | /* Avoid infinite loops when nothing gets converted */ |
| | | if (oldinbytesleft == inbytesleft) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | SDL_iconv_close(cd); |
| | | |