[patch, libfortran] Fix for PR 21593
Thomas Koenig
Thomas.Koenig@online.de
Mon Jul 11 20:52:00 GMT 2005
Hi,
this fixes PR 21593. It is regression-tested on i686-pc-linux-gnu.
I'd appreciate if somebody could actually test it on a system on
which dev_null.f90 fails (Steve?).
2005-07-11 Thomas Koenig <Thomas.Koenig@online.de>
io/unix.c: Add member special_file to type unix_stream.
(fd_truncate): Don't call ftruncate or chsize if
s refers to a special file.
(fd_to_stream): initialize s->special_file.
2005-07-11 Thomas Koenig <Thomas.Koenig@online.de>
dev_null.f90: Remove targets.
-------------- next part --------------
Index: unix.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/unix.c,v
retrieving revision 1.29
diff -c -p -r1.29 unix.c
*** unix.c 18 Jun 2005 20:09:28 -0000 1.29
--- unix.c 11 Jul 2005 20:39:14 -0000
*************** typedef struct
*** 138,143 ****
--- 138,145 ----
int prot;
int ndirty; /* Dirty bytes starting at dirty_offset */
+ int special_file; /* =1 if the fd refers to a special file */
+
unsigned unbuffered:1, mmaped:1;
char small_buffer[BUFFER_SIZE];
*************** fd_truncate (unix_stream * s)
*** 509,521 ****
return FAILURE;
/* non-seekable files, like terminals and fifo's fail the lseek.
! the fd is a regular file at this point */
!
#ifdef HAVE_FTRUNCATE
! if (ftruncate (s->fd, s->logical_offset))
#else
#ifdef HAVE_CHSIZE
! if (chsize (s->fd, s->logical_offset))
#endif
#endif
{
--- 511,524 ----
return FAILURE;
/* non-seekable files, like terminals and fifo's fail the lseek.
! Using ftruncate on a seekable special file (like /dev/null)
! is undefined, so we treat it as if the ftruncate failed.
! */
#ifdef HAVE_FTRUNCATE
! if (s->special_file || ftruncate (s->fd, s->logical_offset))
#else
#ifdef HAVE_CHSIZE
! if (s->special_file || chsize (s->fd, s->logical_offset))
#endif
#endif
{
*************** fd_to_stream (int fd, int prot, int avoi
*** 915,920 ****
--- 918,924 ----
fstat (fd, &statbuf);
s->file_length = S_ISREG (statbuf.st_mode) ? statbuf.st_size : -1;
+ s->special_file = !S_ISREG (statbuf.st_mode);
#if HAVE_MMAP
if (avoid_mmap)
-------------- next part --------------
Index: dev_null.f90
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gfortran.dg/dev_null.f90,v
retrieving revision 1.2
diff -c -p -r1.2 dev_null.f90
*** dev_null.f90 28 Jun 2005 12:51:09 -0000 1.2
--- dev_null.f90 11 Jul 2005 20:49:37 -0000
***************
*** 1,4 ****
! ! { dg-do run { target *-*-linux* *-*-solaris* } }
! This test currently only runs on systems where using ftruncate on
! /dev/null fails (errno set to EINVAL). See PR 21593 for details.
!
--- 1,4 ----
! ! { dg-do run }
! This test currently only runs on systems where using ftruncate on
! /dev/null fails (errno set to EINVAL). See PR 21593 for details.
!
More information about the Fortran
mailing list