aboutsummaryrefslogtreecommitdiff
path: root/toys/pending
diff options
context:
space:
mode:
authorFelix Janda <felix.janda@posteo.de>2014-05-31 11:18:30 +0200
committerFelix Janda <felix.janda@posteo.de>2014-05-31 11:18:30 +0200
commitc20fb908bb733a3d7c1dda77a3c1d22d5c3fafec (patch)
tree74af9dba999dd4d2dc906aad1a24f70166727734 /toys/pending
parentf71abed76bd2eacc6ebf43663059631c7cf213ed (diff)
downloadtoybox-c20fb908bb733a3d7c1dda77a3c1d22d5c3fafec.tar.gz
iconv: some fixes
- fix problem with sequences at buffer boundaries - add (ignored) -c and -s options - don't try to continue with a file when read() fails
Diffstat (limited to 'toys/pending')
-rw-r--r--toys/pending/iconv.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/toys/pending/iconv.c b/toys/pending/iconv.c
index a24abcd9..77b80382 100644
--- a/toys/pending/iconv.c
+++ b/toys/pending/iconv.c
@@ -4,7 +4,7 @@
*
* See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/iconv.html
-USE_ICONV(NEWTOY(iconv, "t:f:", TOYFLAG_USR|TOYFLAG_BIN))
+USE_ICONV(NEWTOY(iconv, "cst:f:", TOYFLAG_USR|TOYFLAG_BIN))
config ICONV
bool "iconv"
@@ -38,16 +38,19 @@ static void do_iconv(int fd, char *name)
do {
size_t outleft = 2048;
- char *in = toybuf, *out = outstart;
+ char *in = toybuf+inleft, *out = outstart;
- len = read(fd, toybuf+inleft, 2048-inleft);
+ len = read(fd, in, 2048-inleft);
- if (len < 0) perror_msg("read '%s'");
+ if (len < 0) {
+ perror_msg("read '%s'");
+ return;
+ }
inleft += len;
do {
if (iconv(TT.ic, &in, &inleft, &out, &outleft) == -1
- && (errno == EILSEQ || (in == toybuf && errno == EINVAL)))
+ && (errno == EILSEQ || (in == toybuf+inleft-len && errno == EINVAL)))
{
if (outleft) {
// Skip first byte of illegal sequence to avoid endless loops