This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gfortran] patch for pr19478 (read from /dev/null)
- From: Bud Davis <bdavis at gfortran dot org>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, gfortran <fortran at gcc dot gnu dot org>
- Date: Sun, 30 Jan 2005 09:16:33 -0600
- Subject: [gfortran] patch for pr19478 (read from /dev/null)
this PR demonstrated that you could apparently write a string to
/dev/null and then read it back.
updated the file position variables in the I/O library when the
ftruncate fails. this makes the buffering scheme work as expected.
tested i686/gnu/linux and amd64/gnu/linux with no additional testsuite
failures.
no change to NIST testsuite.
--bud
2005-01-30 Bud Davis <bdavis@gfortran.org>
PR fortran/19478
* io/unix.c (fd_truncate): update positions when ftruncate
fails (like writing to /dev/null).
Index: gcc/libgfortran/io/unix.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/unix.c,v
retrieving revision 1.21
diff -c -3 -p -r1.21 unix.c
*** gcc/libgfortran/io/unix.c 23 Jan 2005 00:14:31 -0000 1.21
--- gcc/libgfortran/io/unix.c 30 Jan 2005 14:44:44 -0000
*************** fd_truncate (unix_stream * s)
*** 514,520 ****
the fd is a regular file at this point */
if (ftruncate (s->fd, s->logical_offset))
! return FAILURE;
s->physical_offset = s->file_length = s->logical_offset;
--- 514,523 ----
the fd is a regular file at this point */
if (ftruncate (s->fd, s->logical_offset))
! {
! s->physical_offset = s->file_length = 0;
! return FAILURE;
! }
s->physical_offset = s->file_length = s->logical_offset;
! { dg-do run }
! pr19478 read from /dev/null
! Thomas.Koenig@online.de
character*20 foo
open(10,file="/dev/null")
write(10,'(A)') "Hello"
rewind(10)
read(10,'(A)',end=100) foo
call abort
100 continue
end