diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index df9d597793c..b23124664e3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-03-29 Tobias Burnus + + PR fortran/43551 + * gfortran.dg/direct_io_12.f90: New test. + 2010-03-28 Jan Hubicka 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 index 00000000000..53367027242 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/direct_io_12.f90 @@ -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 + diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index b13f107f736..4958831010e 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,8 @@ +2010-03-29 Tobias Burnus + + PR fortran/43551 + * io/unix.c (buf_write): Set physical_offset after lseek. + 2010-03-25 Jerry DeLisle PR libfortran/43517 diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index 4435674b46d..ea3b8bc4b40 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -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. */