This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[libgfortran,patch] Flush open units before SYSTEM call
- From: "François-Xavier Coudert" <fxcoudert at gmail dot com>
- To: gfortran <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 7 May 2007 12:37:16 +0200
- Subject: [libgfortran,patch] Flush open units before SYSTEM call
Attached patch fixes PR31607 ("CALL SYSTEM produces garbled output
when writing to a buffered file") by flushing all open units before
performing a SYSTEM call (the call is done in the library routine for
SYSTEM). This ensures that the output from the SYSTEM call is not
mixed with other output, consistently with the behaviour of other
compilers (Intel, Sun, g95 to name a few).
Bootstrapped and regtested on i686-linux, OK for mainline?
FX
:ADDPATCH libgfortran:
2007-05-07 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
* intrinsics/system.c (system_sub): Call flush_all_units.
* io/io.h (flush_all_units): Move prototype to libgfortran.h.
* libgfortran.h (flush_all_units): Add prototype.
Index: intrinsics/system.c
===================================================================
--- intrinsics/system.c (revision 124460)
+++ intrinsics/system.c (working copy)
@@ -49,6 +49,9 @@ system_sub (const char *fcmd, GFC_INTEGE
char cmd[cmd_len + 1];
int stat;
+ /* Flush all I/O units before executing the command. */
+ flush_all_units();
+
memcpy (cmd, fcmd, cmd_len);
cmd[cmd_len] = '\0';
Index: libgfortran.h
===================================================================
--- libgfortran.h (revision 124460)
+++ libgfortran.h (working copy)
@@ -658,6 +658,11 @@ internal_proto(fstrcpy);
extern void cf_strcpy (char *, int, const char *);
internal_proto(cf_strcpy);
+/* io/intrinsics.c */
+
+extern void flush_all_units (void);
+internal_proto(flush_all_units);
+
/* io.c */
extern void init_units (void);
Index: io/io.h
===================================================================
--- io/io.h (revision 124460)
+++ io/io.h (working copy)
@@ -586,9 +586,6 @@ internal_proto(compare_file_filename);
extern gfc_unit *find_file (const char *file, gfc_charlen_type file_len);
internal_proto(find_file);
-extern void flush_all_units (void);
-internal_proto(flush_all_units);
-
extern int stream_at_bof (stream *);
internal_proto(stream_at_bof);