In iconv case, only expand the buffer when we really need more space. Correctly handle all output when flushing iconv.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17172 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Alexander Malmberg 2003-07-08 01:50:42 +00:00
parent 568aca9d71
commit dd482c40f6
2 changed files with 14 additions and 24 deletions

View file

@ -1,3 +1,9 @@
2003-07-08 03:44 Alexander Malmberg <alexander@malmberg.org>
* Source/Additions/Unicode.m (GSToUnicode, GSFromUnicode): In iconv
case, only try to expand the buffer when we really need extra space.
Correctly handle all output from flushing iconv.
2003-07-08 03:03 Alexander Malmberg <alexander@malmberg.org>
* Source/NSConnection.m (-locateLocalTarget:): The targetToCached

View file

@ -1268,19 +1268,11 @@ tables:
inbytesleft = slen;
outbuf = (char*)ptr;
outbytesleft = bsize * sizeof(unichar);
while (done == NO)
do
{
if (dpos >= bsize)
{
unsigned old = bsize;
GROW();
outbuf = (char*)&ptr[dpos];
outbytesleft += (bsize - old) * sizeof(unichar);
}
if (inbytesleft == 0)
{
done = YES; // Flush iconv, then terminate.
done = YES; // Flush iconv
rval = iconv(cd, 0, 0, &outbuf, &outbytesleft);
}
else
@ -1305,7 +1297,7 @@ tables:
break;
}
}
}
} while (!done || rval != 0);
// close the converter
iconv_close(cd);
}
@ -1537,7 +1529,7 @@ GSFromUnicode(unsigned char **dst, unsigned int *size, const unichar *src,
unsigned ltsize = 0;
BOOL swapped = NO;
BOOL result = YES;
if (options & GSUniBOM)
{
if (slen == 0)
@ -1858,19 +1850,11 @@ tables:
inbytesleft = slen * sizeof(unichar);
outbuf = (char*)ptr;
outbytesleft = bsize;
while (done == NO)
do
{
if (dpos >= bsize)
{
unsigned old = bsize;
GROW();
outbuf = (char*)&ptr[dpos];
outbytesleft += (bsize - old);
}
if (inbytesleft == 0)
{
done = YES; // Flush buffer, then terminate.
done = YES; // Flush buffer
rval = iconv(cd, 0, 0, &outbuf, &outbytesleft);
}
else
@ -1927,11 +1911,11 @@ tables:
break;
}
}
}
} while (!done || rval != 0);
// close the converter
iconv_close(cd);
}
#else
#else
result = NO;
break;
#endif