Improve interactive behaviour of iconv program.
diff --git a/ChangeLog b/ChangeLog
index 3b15f4b..af162dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2011-07-03  Bruno Haible  <bruno@clisp.org>
 
+	Improve interactive behaviour of iconv program.
+	* src/iconv.c (convert): Flush the output before starting a possibly
+	blocking safe_read call.
+
+2011-07-03  Bruno Haible  <bruno@clisp.org>
+
 	Fix interactive behaviour of iconv program.
 	* Makefile.devel (GNULIB_MODULES): Add safe-read.
 	* src/iconv.c: Include safe-read.h.
diff --git a/src/iconv.c b/src/iconv.c
index cfb88cc..d85ae27 100644
--- a/src/iconv.c
+++ b/src/iconv.c
@@ -684,7 +684,11 @@
   line = 1; column = 0;
   iconv(cd,NULL,NULL,NULL,NULL);
   for (;;) {
-    size_t inbufsize = safe_read(infile,inbuf+4096,4096);
+    size_t inbufsize;
+    /* Transfer the accumulated output to its destination, in case the
+       safe_read() call will block. */
+    fflush(stdout);
+    inbufsize = safe_read(infile,inbuf+4096,4096);
     if (inbufsize == 0 || inbufsize == SAFE_READ_ERROR) {
       infile_error = (inbufsize == SAFE_READ_ERROR ? errno : 0);
       if (inbufrest == 0)