From ac0ff196648e91cf0d6f45a318b81fe23d7ebbaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 17 Jan 2007 11:18:33 +0000 Subject: [PATCH] While investigating why our UTF-16 files are broken (with a smaller output buffer), I noticed that "state" was never set, but as expected this doesn't help at all: we just can't use iconv() this way, I'll open a bug for this. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19844 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/textencoding/utf8_conversions.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/kits/textencoding/utf8_conversions.cpp b/src/kits/textencoding/utf8_conversions.cpp index 485ba9235d..7f52e94bce 100644 --- a/src/kits/textencoding/utf8_conversions.cpp +++ b/src/kits/textencoding/utf8_conversions.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2006, Haiku, Inc. All Rights Reserved. + * Copyright 2003-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -40,17 +40,24 @@ convert_encoding(const char* from, const char* to, const char* src, return B_OK; } + // TODO: this doesn't work, as the state is reset every time! iconv_t conversion = iconv_open(to, from); if (conversion == (iconv_t)-1) { DEBPRINT(("iconv_open failed\n")); return B_ERROR; } - if (state == NULL || *state == 0) - iconv(conversion, 0, 0, 0, 0); + + size_t outputLeft = *dstLen; + + if (state == NULL || *state == 0) { + if (state != NULL) + *state = 1; + + iconv(conversion, NULL, NULL, &dst, &outputLeft); + } char** inputBuffer = const_cast(&src); size_t inputLeft = *srcLen; - size_t outputLeft = *dstLen; do { size_t nonReversibleConversions = iconv(conversion, inputBuffer, &inputLeft, &dst, &outputLeft);