OSDN Git Service

2010-03-29 Tobias Burnus <burnus@net-b.de>
authorburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 29 Mar 2010 06:17:19 +0000 (06:17 +0000)
committerburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 29 Mar 2010 06:17:19 +0000 (06:17 +0000)
        PR fortran/43551
        * io/unix.c (buf_write): Set physical_offset after lseek.

2010-03-29  Tobias Burnus  <burnus@net-b.de>

        PR fortran/43551
        * gfortran.dg/direct_io_12.f90: New test.

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

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/direct_io_12.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/io/unix.c

index df9d597..b231246 100644 (file)
@@ -1,3 +1,8 @@
+2010-03-29  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/43551
+       * gfortran.dg/direct_io_12.f90: New test.
+
 2010-03-28  Jan Hubicka  <jh@suse.cz>
 
        PR tree-optimization/43505
diff --git a/gcc/testsuite/gfortran.dg/direct_io_12.f90 b/gcc/testsuite/gfortran.dg/direct_io_12.f90
new file mode 100644 (file)
index 0000000..5336702
--- /dev/null
@@ -0,0 +1,33 @@
+! { dg-do run }
+! 
+! PR fortran/43551
+!
+! Writes a 672000 byte file with buffering. The writing failed because
+! of a missing lseek.
+
+implicit none
+integer, parameter :: size = 2800 ! << needs to be large enough
+real(8) :: vec1(size,30), dummy(size)
+integer i
+
+CALL RANDOM_NUMBER(vec1)
+
+open(99, file='test.dat', form='unformatted', access='direct', recl=size*8)
+do i = 1, 10
+  write(99,rec=i) vec1(:,i)
+  write(99,rec=i+10) vec1(:,i+10)
+  write(99,rec=i+20) vec1(:,i+20) ! << rec = 30 was written to rec = 21
+end do
+
+do i = 1, 10
+  read(99,rec=i) dummy
+  if (any (dummy /= vec1(:,i))) call abort()
+  read(99,rec=i+10) dummy
+  if (any (dummy /= vec1(:,i+10))) call abort()
+  read(99,rec=i+20) dummy
+  if (any (dummy /= vec1(:,i+20))) call abort() ! << aborted here for rec = 21
+end do
+
+close(99, status='delete')
+end
+
index b13f107..4958831 100644 (file)
@@ -1,3 +1,8 @@
+2010-03-29  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/43551
+       * io/unix.c (buf_write): Set physical_offset after lseek.
+
 2010-03-25  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libfortran/43517
index 4435674..ea3b8bc 100644 (file)
@@ -496,13 +496,17 @@ buf_write (unix_stream * s, const void * buf, ssize_t nbyte)
           s->ndirty += nbyte;
         }
       else
-        {
-          if (s->file_length != -1 && s->physical_offset != s->logical_offset
-              && lseek (s->fd, s->logical_offset, SEEK_SET) < 0)
-            return -1;
-          nbyte = raw_write (s, buf, nbyte);
-          s->physical_offset += nbyte;
-        }
+       {
+         if (s->file_length != -1 && s->physical_offset != s->logical_offset)
+           {
+             if (lseek (s->fd, s->logical_offset, SEEK_SET) < 0)
+               return -1;
+             s->physical_offset = s->logical_offset;
+           }
+
+         nbyte = raw_write (s, buf, nbyte);
+         s->physical_offset += nbyte;
+       }
     }
   s->logical_offset += nbyte;
   /* Don't increment file_length if the file is non-seekable.  */