diff options
-rw-r--r-- | miscutils/iconv.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/miscutils/iconv.c b/miscutils/iconv.c index ec3c0c92d..debb45704 100644 --- a/miscutils/iconv.c +++ b/miscutils/iconv.c | |||
@@ -1717,6 +1717,7 @@ int iconv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
1717 | int iconv_main(int argc, char **argv) | 1717 | int iconv_main(int argc, char **argv) |
1718 | { | 1718 | { |
1719 | const char *fromcode = "", *tocode = "", *outfile; | 1719 | const char *fromcode = "", *tocode = "", *outfile; |
1720 | char *tmpname = NULL; | ||
1720 | int i, opt; | 1721 | int i, opt; |
1721 | iconv_t cd; | 1722 | iconv_t cd; |
1722 | FILE *in; | 1723 | FILE *in; |
@@ -1733,8 +1734,11 @@ int iconv_main(int argc, char **argv) | |||
1733 | return 0; | 1734 | return 0; |
1734 | } | 1735 | } |
1735 | 1736 | ||
1736 | if (opt & OPT_o) | 1737 | if (opt & OPT_o) { |
1737 | out = xfopen(outfile, "wb"); | 1738 | tmpname = xasprintf("%sXXXXXX", outfile); |
1739 | mktemp(tmpname); | ||
1740 | out = xfopen(tmpname, "wb"); | ||
1741 | } | ||
1738 | 1742 | ||
1739 | if (opt & OPT_c) | 1743 | if (opt & OPT_c) |
1740 | tocode = xasprintf("%s//IGNORE", tocode); | 1744 | tocode = xasprintf("%s//IGNORE", tocode); |
@@ -1755,6 +1759,11 @@ int iconv_main(int argc, char **argv) | |||
1755 | fclose(in); | 1759 | fclose(in); |
1756 | } | 1760 | } |
1757 | 1761 | ||
1762 | if (tmpname) { | ||
1763 | fclose(out); | ||
1764 | xrename(tmpname, outfile); | ||
1765 | } | ||
1766 | |||
1758 | if (ENABLE_FEATURE_CLEAN_UP) | 1767 | if (ENABLE_FEATURE_CLEAN_UP) |
1759 | iconv_close(cd); | 1768 | iconv_close(cd); |
1760 | return 0; | 1769 | return 0; |