|
发表于 2005-10-9 13:10:32
|
显示全部楼层
[code:1]
char *charset_convert (char *str_in, const char *to_codeset, const char *from_codeset)
{
#define OUTBUF_SIZE 1024
iconv_t cd;
char *outbuf;
char *outptr;
size_t outlen;
size_t inlen;
size_t n;
cd = iconv_open(to_codeset, from_codeset);
if(cd == (iconv_t)-1)
return NULL;
outbuf = (char *)malloc(OUTBUF_SIZE);
if(!outbuf)
return NULL;
memset(outbuf,0,OUTBUF_SIZE);
outptr = outbuf;
inlen = strlen(str_in);
outlen = OUTBUF_SIZE;
n = iconv (cd, &str_in, &inlen, &outptr, &outlen);
if(n < 0)
{
free(outbuf);
return NULL;
}
else
return outbuf;
}
[/code:1] |
|