9 int main(int ac, char **av)
12 size_t inbytes = 0, outbytes = 0;
13 const char *from_enc = av[1], *to_enc = av[2];
14 char *input, *output, *inbfr, *outbfr;
17 fprintf(stderr,"usage: chrset from-enc to-enc < infile > outfile\n");
20 if( fstat(fileno(stdin), &st) || !st.st_size ) {
21 fprintf(stderr, "cant stat stdin\n");
26 cd = iconv_open(to_enc, from_enc);
27 if( cd == (iconv_t)-1 ) {
28 fprintf(stderr, "Conversion from %s to %s is not available",
33 inbfr = input = malloc(inbytes);
34 read(0,input,inbytes);
35 outbytes = inbytes*2 + inbytes/2;
36 outbfr = output = malloc(outbytes);
37 iconv(cd, &input, &inbytes, &output, &outbytes);
39 write(1,outbfr,output-outbfr);