When we do not have a direct iconv handle between any two charsets, we
must go iva UTF16. However, we should still return the same buffer
and error code as if we were able to go direct - including the partial
conversion and the error code.
This is important for locating the invalid multibyte character in the
stream, for example.
Andrew Bartlett
Signed-off-by: Andrew Tridgell <tridge@samba.org>
while (*inbytesleft > 0) {
char *bufp1 = cvtbuf;
const char *bufp2 = cvtbuf;
-
+ int saved_errno = errno;
+ bool pull_failed = false;
bufsize = SMB_ICONV_BUFSIZE;
if (cd->pull(cd->cd_pull,
inbuf, inbytesleft, &bufp1, &bufsize) == -1
&& errno != E2BIG) {
- talloc_free(cvtbuf);
- return -1;
+ saved_errno = errno;
+ pull_failed = true;
}
bufsize = SMB_ICONV_BUFSIZE - bufsize;
outbuf, outbytesleft) == -1) {
talloc_free(cvtbuf);
return -1;
+ } else if (pull_failed) {
+ /* We want the pull errno if possible */
+ errno = saved_errno;
+ return -1;
}
}
talloc_free(cvtbuf);