diff options
author | Ron Yorston <rmy@pobox.com> | 2023-11-08 15:21:25 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-11-08 15:21:25 +0000 |
commit | 5085fe5d56e63f23f9812bd120a8453bd6589edc (patch) | |
tree | 5e71030065aff947ecc87ef20da0e838324073b3 | |
parent | 4e21b98252d61c524048f6b1d561aba522ed5baa (diff) | |
download | busybox-w32-5085fe5d56e63f23f9812bd120a8453bd6589edc.tar.gz busybox-w32-5085fe5d56e63f23f9812bd120a8453bd6589edc.tar.bz2 busybox-w32-5085fe5d56e63f23f9812bd120a8453bd6589edc.zip |
iconv: fix incorrect fix
Part of commit 412c2cab62 (iconv: minor fixes) was intended to
avoid having to enter ^Z twice to signal EOF when input was coming
from the console. Unfortunately there were unintended consequences.
Use a different method to detect EOF.
Costs 32-48 bytes.
(GitHuv issue #374)
-rw-r--r-- | miscutils/iconv.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/miscutils/iconv.c b/miscutils/iconv.c index debb45704..bedbb718d 100644 --- a/miscutils/iconv.c +++ b/miscutils/iconv.c | |||
@@ -1677,25 +1677,26 @@ static void process_file(iconv_t cd, FILE *in, FILE *out) | |||
1677 | char outbuf[BUFSIZ]; | 1677 | char outbuf[BUFSIZ]; |
1678 | const char *pin; | 1678 | const char *pin; |
1679 | char *pout; | 1679 | char *pout; |
1680 | size_t inbytesleft = 0; | 1680 | size_t inbytesleft; |
1681 | size_t outbytesleft; | 1681 | size_t outbytesleft; |
1682 | size_t rest = 0; | 1682 | size_t rest = 0; |
1683 | size_t r; | 1683 | size_t r; |
1684 | 1684 | ||
1685 | while ((!feof(in) && | 1685 | while ((inbytesleft=fread(inbuf+rest, 1, sizeof(inbuf)-rest, in)) != 0 |
1686 | (inbytesleft=fread(inbuf+rest, 1, sizeof(inbuf)-rest, in)) != 0) | ||
1687 | || rest != 0) { | 1686 | || rest != 0) { |
1688 | inbytesleft += rest; | 1687 | inbytesleft += rest; |
1689 | pin = inbuf; | 1688 | pin = inbuf; |
1690 | pout = outbuf; | 1689 | pout = outbuf; |
1691 | outbytesleft = sizeof(outbuf); | 1690 | outbytesleft = sizeof(outbuf); |
1692 | r = iconv(cd, &pin, &inbytesleft, &pout, &outbytesleft); | 1691 | r = iconv(cd, &pin, &inbytesleft, &pout, &outbytesleft); |
1692 | fwrite(outbuf, 1, sizeof(outbuf) - outbytesleft, out); | ||
1693 | if (r == (size_t)(-1) && errno != E2BIG && | 1693 | if (r == (size_t)(-1) && errno != E2BIG && |
1694 | (errno != EINVAL || feof(in))) | 1694 | (errno != EINVAL || feof(in))) |
1695 | bb_perror_msg_and_die("conversion error"); | 1695 | bb_perror_msg_and_die("conversion error"); |
1696 | fwrite(outbuf, 1, sizeof(outbuf) - outbytesleft, out); | ||
1697 | memmove(inbuf, pin, inbytesleft); | 1696 | memmove(inbuf, pin, inbytesleft); |
1698 | rest = inbytesleft; | 1697 | rest = inbytesleft; |
1698 | if (rest == 0 && feof(in)) | ||
1699 | break; | ||
1699 | } | 1700 | } |
1700 | pout = outbuf; | 1701 | pout = outbuf; |
1701 | outbytesleft = sizeof(outbuf); | 1702 | outbytesleft = sizeof(outbuf); |