changeset 3985:2f8efcf14c83 SDL-1.2

Okay, apparently the newer standard specifies char** for the inbuf parameter to iconv() (See http://lists.debian.org/debian-glibc/2004/05/msg00006.html) I'm casting in the general case, but I added a non-const codepath in case it matters on some platform.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 28 Jun 2007 06:47:35 +0000
parents b74530a1dad6
children 4f73308bbb32
files src/stdlib/SDL_iconv.c
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/stdlib/SDL_iconv.c	Thu Jun 28 05:35:50 2007 +0000
+++ b/src/stdlib/SDL_iconv.c	Thu Jun 28 06:47:35 2007 +0000
@@ -34,7 +34,20 @@
                  const char **inbuf, size_t *inbytesleft,
                  char **outbuf, size_t *outbytesleft)
 {
-	size_t retCode = iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft);
+	size_t retCode;
+#ifdef ICONV_REALLY_MODIFIES_INBUF
+	if ( inbuf && *inbuf && inbytesleft ) {
+		char *tmp = SDL_stack_alloc(char, *inbytesleft);
+		char *ptr = tmp;
+		retCode = iconv(cd, &ptr, inbytesleft, outbuf, outbytesleft);
+		inbuf += (ptr - tmp);
+		SDL_stack_free(tmp);
+	} else {
+		retCode = iconv(cd, NULL, inbytesleft, outbuf, outbytesleft);
+	}
+#else
+	retCode = iconv(cd, (char **)inbuf, inbytesleft, outbuf, outbytesleft);
+#endif
 	if ( retCode == (size_t)-1 ) {
 		switch(errno) {
 		    case E2BIG: