This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[gfortran] patch for pr19872
- From: Bud Davis <bdavis at gfortran dot org>
- To: gfortran <fortran at gcc dot gnu dot org>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 19 Feb 2005 21:06:49 -0600
- Subject: [gfortran] patch for pr19872
need to truncate a sequential file on the first write, in case it has
more data in it than we are going to write.
no regression i686/gnu/linux. no changes to NIST test suite.
--bud
2004-02-20 Bud Davis <bdavis@gfortran.org>
PR fortran/19872
* io/transfer.c (data_transfer_init): truncate an existing
file on the first write.
? gcc/gcc/fortran/.decl.c.swp
Index: gcc/libgfortran/io/transfer.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/transfer.c,v
retrieving revision 1.31
diff -c -3 -p -r1.31 transfer.c
*** gcc/libgfortran/io/transfer.c 29 Jan 2005 15:45:17 -0000 1.31
--- gcc/libgfortran/io/transfer.c 20 Feb 2005 02:25:14 -0000
*************** data_transfer_init (int read_flag)
*** 1097,1102 ****
--- 1097,1109 ----
generate_error (ERROR_OS, NULL);
}
+ /* Overwriting an existing sequential file ?
+ it is always safe to truncate the file on the first write */
+ if (g.mode == WRITING
+ && current_unit->flags.access == ACCESS_SEQUENTIAL
+ && current_unit->current_record == 0)
+ struncate(current_unit->s);
+
current_unit->mode = g.mode;
/* Set the initial value of flags. */
! { dg-do run }
! PR 19872 - closed and re-opened file not overwriten
implicit none
integer i(4)
data i / 4 * 0 /
open(1,form='FORMATTED',status='UNKNOWN')
write(1,'("1 2 3 4 5 6 7 8 9")')
close(1)
open(1,form='FORMATTED')
write(1,'("9 8 7 6")')
close(1)
open(1,form='FORMATTED')
read(1,*)i
if(i(1).ne.9.and.i(2).ne.8.and.i(3).ne.7.and.i(4).ne.9)call abort
print*,i
read(1,*,end=200)i
! should only be able to read one line from the file
call abort
200 continue
close(1,STATUS='DELETE')
stop
end