diff options
author | Luo Jinghua <sunmoon1997@gmail.com> | 2010-01-07 23:11:44 +0800 |
---|---|---|
committer | Luo Jinghua <sunmoon1997@gmail.com> | 2010-01-07 23:11:44 +0800 |
commit | e6912026b88e80bf93b88a41bf0af472b8a2663c (patch) | |
tree | 5f03fb1e69cee4045fd37dd51a3faa0cc5304d96 | |
parent | b6b18e634489ee0ec1b3155341ab214922eda4da (diff) |
uconv: print error messages to stderr instead of stdout
-rw-r--r-- | uconv.c | 30 |
1 files changed, 25 insertions, 5 deletions
@@ -19,6 +19,15 @@ int main(int argc, char **argv) from = argv[1]; to = argv[2]; + + conv = uniconv_open(from, to); + if (!conv) { + fprintf (stderr, + "Converting from %s to %s is unsupported.\n", + from, to); + return -1; + } + infp = fopen(argv[3], "rb"); if (!infp) return -1; @@ -26,10 +35,6 @@ int main(int argc, char **argv) if (!outfp) return -1; - conv = uniconv_open(from, to); - if (!conv) - return -1; - off = 0; while (!feof(infp)) { int ret; @@ -51,7 +56,7 @@ int main(int argc, char **argv) continue; } if (ret) { - printf ("Failed to convert.\n"); + fprintf (stderr, "Failed to convert.\n"); exit(-1); break; } @@ -62,6 +67,21 @@ int main(int argc, char **argv) off += len; } + while (1) { + char *outp; + int ret; + + outp = outbuffer; + ret = uniconv_conv(conv, NULL, 0, &outp, sizeof(outbuffer)); + if (ret < 0) { + fprintf (stderr, "Failed to flush descriptor.\n"); + break; + } else { + fwrite(outbuffer, 1, outp - outbuffer, outfp); + break; + } + } + fclose(outfp); fclose(infp); |