re PR libfortran/43551 (Buffered direct I/O reads wrong record)

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

        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.

From-SVN: r157793
This commit is contained in:
Tobias Burnus 2010-03-29 08:18:16 +02:00 committed by Tobias Burnus
parent ede56e6177
commit a46fcb3f25
4 changed files with 54 additions and 7 deletions

View 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-27 Joseph Myers <joseph@codesourcery.com>
PR c/43381

View File

@ -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

View 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

View File

@ -454,13 +454,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. */