Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/iconv Save errno around fwrite(), which can otherwis...



details:   https://anonhg.NetBSD.org/src/rev/8b453d7d5584
branches:  trunk
changeset: 790415:8b453d7d5584
user:      dholland <dholland%NetBSD.org@localhost>
date:      Mon Oct 07 02:00:46 2013 +0000

description:
Save errno around fwrite(), which can otherwise trash it; PR 47813.
This appears to fully resolve the problem described in the PR, even
though one might think it wouldn't.

diffstat:

 usr.bin/iconv/iconv.c |  7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diffs (39 lines):

diff -r 5082192faea2 -r 8b453d7d5584 usr.bin/iconv/iconv.c
--- a/usr.bin/iconv/iconv.c     Mon Oct 07 00:16:19 2013 +0000
+++ b/usr.bin/iconv/iconv.c     Mon Oct 07 02:00:46 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iconv.c,v 1.18 2011/10/31 13:27:51 yamt Exp $ */
+/*     $NetBSD: iconv.c,v 1.19 2013/10/07 02:00:46 dholland Exp $ */
 
 /*-
  * Copyright (c)2003 Citrus Project,
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: iconv.c,v 1.18 2011/10/31 13:27:51 yamt Exp $");
+__RCSID("$NetBSD: iconv.c,v 1.19 2013/10/07 02:00:46 dholland Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include <err.h>
@@ -99,6 +99,7 @@
        size_t inbytes, outbytes, ret, invalids;
        iconv_t cd;
        uint32_t flags = 0;
+       int serrno;
 
        if (hide_invalid)
                flags |= __ICONV_F_HIDE_INVALID;
@@ -116,10 +117,12 @@
                        outbytes = OUTBUFSIZE;
                        ret = __iconv(cd, &in, &inbytes, &out, &outbytes,
                            flags, &inval);
+                       serrno = errno;
                        invalids += inval;
                        if (outbytes < OUTBUFSIZE)
                                (void)fwrite(outbuf, 1, OUTBUFSIZE - outbytes,
                                    stdout);
+                       errno = serrno;
                        if (ret == (size_t)-1 && errno != E2BIG) {
                                /*
                                 * XXX: iconv(3) is bad interface.



Home | Main Index | Thread Index | Old Index