aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/io/unix.c
diff options
context:
space:
mode:
authorFrancois-Xavier Coudert <coudert@clipper.ens.fr>2005-10-30 13:48:52 +0100
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>2005-10-30 12:48:52 +0000
commit159840cb8aef55bf2f4068f109ad6f987f31abeb (patch)
treebc65843092bd8c38d837724dae7a759a0d4c5e3e /libgfortran/io/unix.c
parent0d519038a0354f983534037fd9a7d460421e4fd0 (diff)
downloadgcc-159840cb8aef55bf2f4068f109ad6f987f31abeb.zip
gcc-159840cb8aef55bf2f4068f109ad6f987f31abeb.tar.gz
gcc-159840cb8aef55bf2f4068f109ad6f987f31abeb.tar.bz2
re PR libfortran/20179 (cannot mix C and Fortran I/O)
PR libfortran/20179 * io/unix.c (flush_if_preconnected): New function. * io/io.h: Add prototype for flush_if_preconnected. * io/transfer.c (data_transfer_init): Use flush_if_preconnected to workaround buggy mixed C-Fortran code. * gfortran.dg/mixed_io_1.f90: New test. * gfortran.dg/mixed_io_1.c: New file. From-SVN: r106017
Diffstat (limited to 'libgfortran/io/unix.c')
-rw-r--r--libgfortran/io/unix.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c
index 2026a36..0fe8c4b 100644
--- a/libgfortran/io/unix.c
+++ b/libgfortran/io/unix.c
@@ -228,6 +228,23 @@ is_preconnected (stream * s)
return 0;
}
+/* If the stream corresponds to a preconnected unit, we flush the
+ corresponding C stream. This is bugware for mixed C-Fortran codes
+ where the C code doesn't flush I/O before returning. */
+void
+flush_if_preconnected (stream * s)
+{
+ int fd;
+
+ fd = ((unix_stream *) s)->fd;
+ if (fd == STDIN_FILENO)
+ fflush (stdin);
+ else if (fd == STDOUT_FILENO)
+ fflush (stdout);
+ else if (fd == STDERR_FILENO)
+ fflush (stderr);
+}
+
/* Reset a stream after reading/writing. Assumes that the buffers have
been flushed. */