Steffen Nurpmeso wrote, on 11 Dec 2020:
>
> Geoff Clare wrote in
> <20201211100245.GA1627@localhost>:
> |Steffen Nurpmeso wrote, on 10 Dec 2020:
> |>
> |> While talking about iconv, i got closed glibc bug[1] as "resolved
> |> invalid", but wouldn't you all agree that in the following
> |>
> |> #include <stdio.h>
> |> #include <string.h>
> |> #include <iconv.h>
> |> #include <errno.h>
> |> int main(void){
> |> char inb[16], oub[16], *inbp, *oubp;
> |> iconv_t id;
> |> size_t inl, oul;
> |>
> |> memcpy(inbp = inb, "a\303\244c", sizeof("a\303\244c"));
> |> inl = sizeof("a\303\244c") -1;
> |> oul = sizeof oub;
> |> oubp = oub;
> |>
> |> if((id = iconv_open("ascii", "utf8")) == (iconv_t)-1)
> |> return 1;
> |> fprintf(stderr, "Converting %lu <%s>\n",(unsigned long)inl, inbp);
> |> if(iconv(id, &inbp, &inl, &oubp, &oul) == (size_t)-1){
> |> fprintf(stderr, "Fail <%s>\n", strerror(errno));
> |> return 2;
> |>}
> |> fprintf(stderr, "GOT <%s>\n", oub);
> |> iconv_close(id);
> |> return 0;
> |>}
> |>
> |> you should get replacement characters out of the box?
> |
> |That depends entirely on how the implementation defines the codeset
> |it calls "ascii" (if it has one at all).
> |
> |If the "ascii" codeset is defined as having 0-127 as the only valid
> |characters, the standard requires that iconv() fails with EILSEQ.
> |If it is defined as having 0-255 as valid characters, the standard
> |requires that all of the input characters are converted.
>
> I think you are mistaken here Geoff, EILSEQ is only defined for
> the source/input character set.
Doh! I had misremembered the iconv_open() arguments as being the
other way round.
Sorry for the noise.
--
Geoff Clare <[email protected]>
The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England