[I bring back austin-group-l, ok? Thorsten Glaser wrote in <pine.bsm.4.64l.2012101900160.29...@herc.mirbsd.org>: |Steffen Nurpmeso dixit: | |> #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; | |Not -1 otherwise oub will not be NUL-terminated and end with junk: | |$ ./a.out |Converting 4 <aäc> |GOT <a?c<� e+x���g��aäc>
Sure thing. Just like below. Normally stack pages are cow forked from zero if i understand that right. But maybe i do not. |Without the trailing NUL, stateful conversation may also be |incomplete… | |> oul = sizeof oub; |> oubp = oub; |> |> if((id = iconv_open("ascii", "utf8")) == (iconv_t)-1) |> return 1; | |Throws 1 because you need "utf-8", but with it, see above. Well names and iconv are a thing. Especially regarding Unicode (and nl_langinfo(CODESET), if i remember UnixWare right). |> 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? | |Citrus iconv agrees. Its manpage says: | | If the string pointed to by *src contains a character which is valid | under the source codeset but can not be converted to the destination | codeset, the character is replaced by an "invalid character" which | depends on the destination codeset, e.g., '?', and the conversion \ | is con- | tinued. iconv() returns the number of such "invalid conversions". That was my thinking. Thanks for confirming this. --End of <pine.bsm.4.64l.2012101900160.29...@herc.mirbsd.org> --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)