X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fi18n.c;h=fa9f29c5835e561354f92877581f0a7ab6f10705;hb=d019e8a29d7963a926837d46ae3592c5731f02e3;hp=eb082c5d94b4f9bc0f798f8f0bf0c17e095d8a81;hpb=425d780e0e2cc08c58722145df4d3dd808f01d48;p=pspp diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c index eb082c5d94..fa9f29c583 100644 --- a/src/libpspp/i18n.c +++ b/src/libpspp/i18n.c @@ -117,6 +117,7 @@ recode_string_pool (const char *to, const char *from, char *outbuf = 0; size_t outbufferlength; size_t result; + char *ip; char *op ; size_t inbytes = 0; size_t outbytes ; @@ -137,10 +138,21 @@ recode_string_pool (const char *to, const char *from, if (from == NULL) from = default_encoding; + conv = create_iconv (to, from); + + if ( (iconv_t) -1 == conv ) + return xstrdup (text); + + /* Put the converter into the initial shift state, in case there was any + state information left over from its last usage. */ + iconv (conv, NULL, 0, NULL, 0); + for ( outbufferlength = 1 ; outbufferlength != 0; outbufferlength <<= 1 ) if ( outbufferlength > length) break; + ip = text; + outbuf = pool_malloc (pool, outbufferlength); op = outbuf; @@ -148,14 +160,8 @@ recode_string_pool (const char *to, const char *from, inbytes = length; - conv = create_iconv (to, from); - - if ( (iconv_t) -1 == conv ) - return xstrdup (text); - do { - const char *ip = text; - result = iconv (conv, (ICONV_CONST char **) &text, &inbytes, + result = iconv (conv, (ICONV_CONST char **) &ip, &inbytes, &op, &outbytes); if ( -1 == result ) @@ -176,13 +182,14 @@ recode_string_pool (const char *to, const char *from, } /* Fall through */ case E2BIG: + iconv (conv, NULL, 0, NULL, 0); pool_free (pool, outbuf); outbufferlength <<= 1; outbuf = pool_malloc (pool, outbufferlength); op = outbuf; outbytes = outbufferlength; inbytes = length; - text = ip; + ip = text; break; default: /* should never happen */