summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuo Jinghua <sunmoon1997@gmail.com>2010-01-07 23:11:44 +0800
committerLuo Jinghua <sunmoon1997@gmail.com>2010-01-07 23:11:44 +0800
commite6912026b88e80bf93b88a41bf0af472b8a2663c (patch)
tree5f03fb1e69cee4045fd37dd51a3faa0cc5304d96
parentb6b18e634489ee0ec1b3155341ab214922eda4da (diff)
uconv: print error messages to stderr instead of stdout
-rw-r--r--uconv.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/uconv.c b/uconv.c
index 80c4866..bd7905e 100644
--- a/uconv.c
+++ b/uconv.c
@@ -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);