This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gfortran] patch for position="append" in open statement (PR libfortran/21471)
- From: FranÃois-Xavier Coudert <Francois-Xavier dot Coudert at lcp dot u-psud dot fr>
- To: gfortran <fortran at gcc dot gnu dot org>, patch <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 10 May 2005 12:22:34 +0200
- Subject: [gfortran] patch for position="append" in open statement (PR libfortran/21471)
Attached is a patch that takes care of POSITION="APPEND" in an OPEN
statement, and a testcase for that matter.
Regtesting in progress on i386-linux. OK for mainline and 4.0 if no regression?
FX
! PR libfortran/21471
! Testing POSITION="APPEND"
!
! { dg-do run }
subroutine failed
close (10,status='delete')
call abort
end subroutine failed
integer,parameter :: n = 13
integer :: i, j, error
open (10, file='foo')
close (10)
do i = 1, n
open (10, file='foo',position='append')
write (10,*) i
close (10)
end do
open (10,file='foo',status='old')
error = 0
i = -1
do while (error == 0)
i = i + 1
read (10,*,iostat=error) j
if (error == 0) then
if (i + 1 /= j) call failed
end if
if (i > n + 1) call failed
end do
if (i /= n) call failed
close (10,status='delete')
end
2005-05-10 Francois-Xavier Coudert <coudert@clipper.ens.fr>
PR libfortran/21471
* open.c (new_unit): Take care of the case where POSITION_APPEND
is specified (sseek to the end, and set u>-endfile).
2005-05-10 Francois-Xavier Coudert <coudert@clipper.ens.fr>
PR libfortran/21471
* gfortran.dg/append-1.f90: New test.
Index: libgfortran/io/open.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/io/open.c,v
retrieving revision 1.12
diff -p -u -r1.12 open.c
--- libgfortran/io/open.c 29 Mar 2005 08:37:32 -0000 1.12
+++ libgfortran/io/open.c 10 May 2005 10:17:42 -0000
@@ -356,6 +356,13 @@ new_unit (unit_flags * flags)
u->s = s;
u->flags = *flags;
+ if (flags->position == POSITION_APPEND)
+ {
+ if (sseek (u->s, file_length (u->s)) == FAILURE)
+ generate_error (ERROR_OS, NULL);
+ u->endfile = AT_ENDFILE;
+ }
+
/* Unspecified recl ends up with a processor dependent value. */
u->recl = (ioparm.recl_in != 0) ? ioparm.recl_in : g.max_offset;