[PATCH] Fix backspace.f (PR libgfortran/20930)
David Edelsohn
dje@watson.ibm.com
Tue Apr 26 18:55:00 GMT 2005
When writing UNFORMATTED records to a buffered stream, libgfortran
does not flush record length markers. data_transfer_init() will flush the
stream when switching from WRITING to READING, but REWIND currectly does
not. If libgfortran I/O seeks past the record length marker in the
stream, the UNIX standard allows the OS to fill the region between the
last write and the seek position with zeroes.
The patch updates st_rewind() to flush the stream when resetting
the mode from WRITING to READING, consistent with the semantics expected
in other parts of the I/O library.
Okay for mainline (and 4.0, if the backspace.c patch is backported)?
Thanks, David
* io/rewind.c (st_rewind): Flush the stream when resetting the mode
from WRITING to READING.
Index: rewind.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/rewind.c,v
retrieving revision 1.9
diff -c -p -r1.9 rewind.c
*** rewind.c 22 Jan 2005 03:51:12 -0000 1.9
--- rewind.c 26 Apr 2005 18:38:30 -0000
*************** st_rewind (void)
*** 55,62 ****
is the last record in the file, so truncate the file now.
Reset to read mode so two consecutive rewind statements
don't delete the file contents. */
! if (u->mode==WRITING)
! struncate(u->s);
u->mode = READING;
u->last_record = 0;
if (sseek (u->s, 0) == FAILURE)
--- 55,65 ----
is the last record in the file, so truncate the file now.
Reset to read mode so two consecutive rewind statements
don't delete the file contents. */
! if (u->mode == WRITING)
! {
! flush (u->s);
! struncate (u->s);
! }
u->mode = READING;
u->last_record = 0;
if (sseek (u->s, 0) == FAILURE)
More information about the Gcc-patches
mailing list