]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
unix.c (fd_alloc_r_at): Use read() instead of do_read() only in case of special files...
authorThomas Koenig <tkoenig@gcc.gnu.org>
Thu, 13 Oct 2005 16:15:30 +0000 (16:15 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Thu, 13 Oct 2005 16:15:30 +0000 (16:15 +0000)
2005-10-13  Thomas Koenig  <Thomas.Koenig@online.de>

* io/unix.c(fd_alloc_r_at):  Use read() instead of do_read()
only in case of special files (e.g. terminals).

From-SVN: r105373

libgfortran/ChangeLog
libgfortran/io/unix.c

index 8afd8717af63bb5ba34593037523aa7923b136a6..16552eedb5e6d055ebac885e016a637db78018de 100644 (file)
@@ -1,3 +1,8 @@
+2005-10-13  Thomas Koenig  <Thomas.Koenig@online.de>
+
+       * io/unix.c(fd_alloc_r_at):  Use read() instead of do_read()
+       only in case of special files (e.g. terminals).
+
 2005-20-13  Uros Bizjak  <uros@kss-loka.si>
 
        * config/fpu-387.h (set_fpu): Add "=m" for stmxcsr.
@@ -26,8 +31,8 @@
 
 2005-10-12  Janne Blomqvist <jblomqvi@cc.hut.fi>
 
-       * io/unix.c: Remove parts of patch of 2005/10/07 that cause
-       input from the terminal to hang.
+       * io/unix.c(fd_alloc_r_at): Remove parts of patch of 2005/10/07 that
+       cause input from the terminal to hang.
 
 2005-10-11  Steven G. Kargl  <kargls@comcast.net>
 
index de018af1f032dba5e588dca6a6d2a2182251e1ed..ea03515f4688210cbe9a135f65a3a94d5df2481f 100644 (file)
@@ -440,7 +440,6 @@ static char *
 fd_alloc_r_at (unix_stream * s, int *len, gfc_offset where)
 {
   gfc_offset m;
-  int n;
 
   if (where == -1)
     where = s->logical_offset;
@@ -462,13 +461,32 @@ fd_alloc_r_at (unix_stream * s, int *len, gfc_offset where)
   if (s->physical_offset != m && lseek (s->fd, m, SEEK_SET) < 0)
     return NULL;
 
-  n = read (s->fd, s->buffer + s->active, s->len - s->active);
-  if (n < 0)
-    return NULL;
+  /* do_read() hangs on read from terminals for *BSD-systems.  Only
+     use read() in that case.  */
+
+  if (s->special_file)
+    {
+      ssize_t n;
+
+      n = read (s->fd, s->buffer + s->active, s->len - s->active);
+      if (n < 0)
+       return NULL;
+
+      s->physical_offset = where + n;
+      s->active += n;
+    }
+  else
+    {
+      size_t n;
 
-  s->physical_offset = where + n;
+      n = s->len - s->active;
+      if (do_read (s, s->buffer + s->active, &n) != 0)
+       return NULL;
+
+      s->physical_offset = where + n;
+      s->active += n;
+    }
 
-  s->active += n;
   if (s->active < *len)
     *len = s->active;          /* Bytes actually available */