#include #include int main () { char output[64]; #ifdef _LIBICONV_VERSION printf ("_LIBICONV_VERSION = 0x%x\n", _LIBICONV_VERSION); #else printf ("_LIBICONV_VERSION is not defined.\n"); #endif iconv_t cd = iconv_open ("ISO-8859-1", "ISO-8859-15"); /* no conversion needed */ { char input[6] = "Oeuvre"; char *inbuf = input; size_t inbytesleft = sizeof (input); char *outbuf = output; size_t outbytesleft = sizeof (output); size_t ret = iconv (cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); printf ("no conversion needed: ret=%d, input consumed: %d/%d, output produced: %d/%d\n", (int) ret, (int) (inbuf - input), (int) (sizeof (input) - inbytesleft), (int) (outbuf - output), (int) (sizeof (output) - outbytesleft)); } /* entire string */ { char input[5] = "\xBCuvre"; char *inbuf = input; size_t inbytesleft = sizeof (input); char *outbuf = output; size_t outbytesleft = sizeof (output); size_t ret = iconv (cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); printf ("entire string: ret=%d, input consumed: %d/%d, output produced: %d/%d\n", (int) ret, (int) (inbuf - input), (int) (sizeof (input) - inbytesleft), (int) (outbuf - output), (int) (sizeof (output) - outbytesleft)); } /* carefully */ { char input[5] = "\xBCuvre"; char *inbuf = input; size_t inbytesleft = 1; char *outbuf = output; size_t outbytesleft = sizeof (output); size_t ret = iconv (cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); printf ("carefully: ret=%d, input consumed: %d/%d, output produced: %d/%d\n", (int) ret, (int) (inbuf - input), (int) (1 - inbytesleft), (int) (outbuf - output), (int) (sizeof (output) - outbytesleft)); } } /* glibc, mingw: _LIBICONV_VERSION is not defined. no conversion needed: ret=0, input consumed: 6/6, output produced: 6/6 entire string: ret=-1, input consumed: 0/0, output produced: 0/0 carefully: ret=-1, input consumed: 0/0, output produced: 0/0 platform with libiconv: _LIBICONV_VERSION = 0x111 no conversion needed: ret=0, input consumed: 6/6, output produced: 6/6 entire string: ret=-1, input consumed: 0/0, output produced: 0/0 carefully: ret=-1, input consumed: 0/0, output produced: 0/0 */