aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/io/unix.c
diff options
context:
space:
mode:
authorThomas Koenig <tkoenig@gcc.gnu.org>2005-10-13 16:15:30 +0000
committerThomas Koenig <tkoenig@gcc.gnu.org>2005-10-13 16:15:30 +0000
commitc1d70e1a522d8c82ca8898a46d746f2f352bf6d5 (patch)
tree7992d61624301cfeea776530b917277c88d522ce /libgfortran/io/unix.c
parent8c210c4104f0296d666aa25f5f904fc14b6da239 (diff)
downloadgcc-c1d70e1a522d8c82ca8898a46d746f2f352bf6d5.zip
gcc-c1d70e1a522d8c82ca8898a46d746f2f352bf6d5.tar.gz
gcc-c1d70e1a522d8c82ca8898a46d746f2f352bf6d5.tar.bz2
unix.c (fd_alloc_r_at): Use read() instead of do_read() only in case of special files (e.g.
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
Diffstat (limited to 'libgfortran/io/unix.c')
-rw-r--r--libgfortran/io/unix.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c
index de018af..ea03515 100644
--- a/libgfortran/io/unix.c
+++ b/libgfortran/io/unix.c
@@ -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 */