From 227e942303e8b1341b3e418d5e28b3280a5b98bf Mon Sep 17 00:00:00 2001
From: tkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 12 Jul 2005 19:52:19 +0000
Subject: [PATCH] 2005-07-12  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-12  Thomas Koenig  <Thomas.Koenig@online.de>

	gfortran.dg/dev_null.f90:  Remove targets.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@101937 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/testsuite/ChangeLog                |  4 ++++
 gcc/testsuite/gfortran.dg/dev_null.f90 |  2 +-
 libgfortran/ChangeLog                  |  7 +++++++
 libgfortran/io/unix.c                  | 12 ++++++++----
 4 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 914f9a513e9e..8cead7dc3d65 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2005-07-11  Thomas Koenig  <Thomas.Koenig@online.de>
+
+	gfortran.dg/dev_null.f90:  Remove targets.
+
 2005-07-12  Andrew Pinski  <pinskia@physics.uc.edu>
 
 	PR tree-opt/22335
diff --git a/gcc/testsuite/gfortran.dg/dev_null.f90 b/gcc/testsuite/gfortran.dg/dev_null.f90
index f9703bc44aa5..c8db001fa1c2 100644
--- a/gcc/testsuite/gfortran.dg/dev_null.f90
+++ b/gcc/testsuite/gfortran.dg/dev_null.f90
@@ -1,4 +1,4 @@
-! { dg-do run { target *-*-linux* *-*-solaris* } }
+! { 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.
 !
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index 28ee7dc0cc0c..e96c422bc3ba 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,10 @@
+2005-07-12  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  David Edelsohn  <edelsohn@gnu.org>
 
         PR libgfortran/22412
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c
index 1158458879e5..b35182d61696 100644
--- a/libgfortran/io/unix.c
+++ b/libgfortran/io/unix.c
@@ -138,6 +138,8 @@ typedef struct
   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];
@@ -509,13 +511,14 @@ fd_truncate (unix_stream * s)
     return FAILURE;
 
   /* non-seekable files, like terminals and fifo's fail the lseek.
-     the fd is a regular file at this point */
-
+     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 (ftruncate (s->fd, s->logical_offset))
+  if (s->special_file || ftruncate (s->fd, s->logical_offset))
 #else
 #ifdef HAVE_CHSIZE
-  if (chsize (s->fd, s->logical_offset))
+  if (s->special_file || chsize (s->fd, s->logical_offset))
 #endif
 #endif
     {
@@ -915,6 +918,7 @@ fd_to_stream (int fd, int prot, int avoid_mmap)
 
   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)
-- 
GitLab