summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-11-19 23:24:33 (GMT)
committer John Mark Bell <jmb@netsurf-browser.org>2008-11-19 23:24:33 (GMT)
commitaf8e8e3c0a0fbf632e8ec2b64b57307a39ce8da8 (patch)
tree1b8eb9dc473c9066c9d84b2d22d54efe14a0ac4c
parent0d5eee8af36bef61f594647d937074fa96b4e324 (diff)
downloadiconv-af8e8e3c0a0fbf632e8ec2b64b57307a39ce8da8.tar.gz
iconv-af8e8e3c0a0fbf632e8ec2b64b57307a39ce8da8.tar.bz2
Make handling of EILSEQ resynchronise stream if we've been asked to ignore errors.
Some kind of handling for failure to read from input file. svn path=/trunk/iconv/; revision=5748
-rw-r--r--module/module.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/module/module.c b/module/module.c
index beaf762..f50d64a 100644
--- a/module/module.c
+++ b/module/module.c
@@ -371,10 +371,14 @@ _kernel_oserror *do_iconv(int argc, const char *args)
size_t outlen = sizeof(output);
/* Fill input buffer */
- fread(input + leftover, 1, inlen - leftover, inf);
+ size_t read = fread(input + leftover, 1,
+ inlen - leftover, inf);
+ /** \todo Do we want better error handling? */
+ if (read < inlen - leftover)
+ break;
/* Convert text */
- size_t read = iconv(cd, &in, &inlen, &out, &outlen);
+ read = iconv(cd, &in, &inlen, &out, &outlen);
if (read == (size_t) -1) {
switch (errno) {
case EILSEQ:
@@ -390,6 +394,18 @@ _kernel_oserror *do_iconv(int argc, const char *args)
fclose(inf);
return NULL;
}
+
+ /* Resynchronise after junk input */
+ while (inlen > 0) {
+ read = iconv(cd, &in, &inlen,
+ &out, &outlen);
+ if (read != (size_t) -1 ||
+ errno != EILSEQ)
+ break;
+
+ in++;
+ inlen--;
+ }
break;
default:
break;