[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: what shall we do about iconv?
Edmund GRIMLEY EVANS writes:
> About a month ago I wrote here that "there seems to be no sensible way
> of implementing a function that converts data while reading it from a
> stream and knows at the end how may non-reversible conversions
> occurred". I tried contacting the Open Group about this, and I
> received some replies from Andrew Josey.
Thanks for telling us; my clarification request about the same issue
was not answered up to now.
> The Group thinks that the specification is clear enough: iconv()
> should return -1 whenever one of the conditions EILSEQ, E2BIG, EINVAL
> or EBADF occurs. Application code is already reliant on this
> behaviour
Now this is clear. Fine.
What an application can do:
a. It can convert one character at a time. If it does this, it can decide
itself about possible default behaviour, transliteration, special colouring
of each misconverted character, or whatever.
b. Often, if EILSEQ or EINVAL occurs, the entire conversion is aborted, and
it does not matter how many non-reversible character conversions were
already made. So all the application has to protect against is E2BIG,
and it can do so by doing the conversion into a temporary buffer first.
So it has to do the conversion twice. But that's life in C. When you
call strdup, it also has to scan the source string twice: once to
determine how much to malloc, and once to do the copying.
Bruno
-
Linux-UTF8: i18n of Linux on all levels
Archive: http://mail.nl.linux.org/lists/