Module Name: src
Committed By: dholland
Date: Mon Oct 7 02:00:46 UTC 2013
Modified Files:
src/usr.bin/iconv: iconv.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/iconv/iconv.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/iconv/iconv.c
diff -u src/usr.bin/iconv/iconv.c:1.18 src/usr.bin/iconv/iconv.c:1.19
--- src/usr.bin/iconv/iconv.c:1.18 Mon Oct 31 13:27:51 2011
+++ src/usr.bin/iconv/iconv.c Mon Oct 7 02:00:46 2013
@@ -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 @@ do_conv(const char *fn, FILE *fp, const
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 @@ do_conv(const char *fn, FILE *fp, const
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.