PR libfortran/21471
authorfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 11 May 2005 05:56:20 +0000 (05:56 +0000)
committerfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 11 May 2005 05:56:20 +0000 (05:56 +0000)
* open.c (new_unit): Take care of the case where POSITION_APPEND
is specified (sseek to the end, and set u>-endfile).
* gfortran.dg/append-1.f90: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@99560 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/append-1.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/io/open.c

index 8e73d94..d92bf93 100644 (file)
@@ -1,3 +1,8 @@
+2005-05-10  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
+
+       PR libfortran/21471
+       * gfortran.dg/append-1.f90: New test.
+
 2005-05-10  Diego Novillo  <dnovillo@redhat.com>
 
        * gcc.dg/pr18501.c: XFAIL.
diff --git a/gcc/testsuite/gfortran.dg/append-1.f90 b/gcc/testsuite/gfortran.dg/append-1.f90
new file mode 100644 (file)
index 0000000..8b81bc3
--- /dev/null
@@ -0,0 +1,36 @@
+! 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
+
index 95884c1..fa866a1 100644 (file)
@@ -1,3 +1,9 @@
+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  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>
 
        PR fortran/20178
index 82a862b..97bf6e4 100644 (file)
@@ -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;