- 论坛徽章:
- 0
|
一测试程序如下:
#include <iconv.h>
#include <string.h>
#include <stdio.h>
#include <sys/stat.h>
int code_convert(char *from_charset,char *to_charset,char *inbuf,int inlen,char *outbuf,int outlen)
{
iconv_t cd;
int rc;
char **pin = &inbuf;
char **pout = &outbuf;
cd = iconv_open(to_charset,from_charset);
if (cd==0){
printf("iconv_open\n" ;
return -1;
}
memset(outbuf,0,outlen);
if (iconv(cd,pin,&inlen,pout,&outlen) == -1)
{
perror("iconv:\n" ;
iconv_close(cd);
return -1;
}
iconv_close(cd);
printf("inlen = %d outlen = %d\n",inlen,outlen);
return 0;
}
int u2g(char *inbuf,int inlen,char *outbuf,int outlen)
{
return code_convert("utf-8","gb2312",inbuf,inlen,outbuf,outlen);
}
int g2u(char *inbuf,size_t inlen,char *outbuf,size_t outlen)
{
//return code_convert("gb2312","utf-8",inbuf,inlen,outbuf,outlen);
//return code_convert("gb18030","utf-8",inbuf,inlen,outbuf,outlen);
return code_convert("gbk","utf-8",inbuf,inlen,outbuf,outlen);
}
int main()
{
char GBK[64]="./你好";
char out[128];
memset(out,0x00,sizeof(out));
g2u(GBK,14,out,12 ;
printf("GBK=%s \n utf=%s \n",GBK,out);
if(mkdir(out, 0755)==-1)
{
printf("mkdir error" ;
return -1;
}
return 0;
}
问题是:在我虚拟机上测试通过,生成一个叫 你好 的目录,但在我板子上运行结果确是(编译通过了)
iconv:
: Bad file descriptor
GBK=./▒▒▒
utf=
|
|