src/stdlib/SDL_iconv.c
branchSDL-1.2
changeset 3987 00486a9c2893
parent 3986 4f73308bbb32
child 3997 6a4f3a32c2e6
equal deleted inserted replaced
3986:4f73308bbb32 3987:00486a9c2893
    25 
    25 
    26 #include "SDL_stdinc.h"
    26 #include "SDL_stdinc.h"
    27 #include "SDL_endian.h"
    27 #include "SDL_endian.h"
    28 
    28 
    29 #ifdef HAVE_ICONV
    29 #ifdef HAVE_ICONV
       
    30 
       
    31 /* Depending on which standard the iconv() was implemented with,
       
    32    iconv() may or may not use const char ** for the inbuf param.
       
    33    If we get this wrong, it's just a warning, so no big deal.
       
    34 */
       
    35 #if defined(_XGP6) || \
       
    36     defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
       
    37 #define ICONV_INBUF_NONCONST
       
    38 #endif
    30 
    39 
    31 #include <errno.h>
    40 #include <errno.h>
    32 
    41 
    33 size_t SDL_iconv(SDL_iconv_t cd,
    42 size_t SDL_iconv(SDL_iconv_t cd,
    34                  const char **inbuf, size_t *inbytesleft,
    43                  const char **inbuf, size_t *inbytesleft,
    35                  char **outbuf, size_t *outbytesleft)
    44                  char **outbuf, size_t *outbytesleft)
    36 {
    45 {
    37 	size_t retCode;
    46 	size_t retCode;
    38 #ifdef ICONV_REALLY_MODIFIES_INBUF
    47 #ifdef ICONV_INBUF_NONCONST
    39 	if ( inbuf && *inbuf && inbytesleft ) {
    48 	retCode = iconv(cd, (char **)inbuf, inbytesleft, outbuf, outbytesleft);
    40 		char *tmp = SDL_stack_alloc(char, *inbytesleft);
       
    41 		char *ptr = tmp;
       
    42 		SDL_memcpy(tmp, inbuf, *inbytesleft);
       
    43 		retCode = iconv(cd, &ptr, inbytesleft, outbuf, outbytesleft);
       
    44 		inbuf += (ptr - tmp);
       
    45 		SDL_stack_free(tmp);
       
    46 	} else {
       
    47 		retCode = iconv(cd, NULL, inbytesleft, outbuf, outbytesleft);
       
    48 	}
       
    49 #else
    49 #else
    50 	retCode = iconv(cd, (char **)inbuf, inbytesleft, outbuf, outbytesleft);
    50 	retCode = iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft);
    51 #endif
    51 #endif
    52 	if ( retCode == (size_t)-1 ) {
    52 	if ( retCode == (size_t)-1 ) {
    53 		switch(errno) {
    53 		switch(errno) {
    54 		    case E2BIG:
    54 		    case E2BIG:
    55 			return SDL_ICONV_E2BIG;
    55 			return SDL_ICONV_E2BIG;