diff options
Diffstat (limited to 'gcc-4.9/libgfortran/io/unix.c')
-rw-r--r-- | gcc-4.9/libgfortran/io/unix.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/gcc-4.9/libgfortran/io/unix.c b/gcc-4.9/libgfortran/io/unix.c index 34c2d0cad..a2df440e2 100644 --- a/gcc-4.9/libgfortran/io/unix.c +++ b/gcc-4.9/libgfortran/io/unix.c @@ -412,7 +412,9 @@ raw_close (unix_stream * s) { int retval; - if (s->fd != STDOUT_FILENO + if (s->fd == -1) + retval = -1; + else if (s->fd != STDOUT_FILENO && s->fd != STDERR_FILENO && s->fd != STDIN_FILENO) retval = close (s->fd); @@ -784,10 +786,10 @@ mem_read4 (stream * s, void * buf, ssize_t nbytes) void *p; int nb = nbytes; - p = mem_alloc_r (s, &nb); + p = mem_alloc_r4 (s, &nb); if (p) { - memcpy (buf, p, nb); + memcpy (buf, p, nb * 4); return (ssize_t) nb; } else @@ -1003,7 +1005,15 @@ fd_to_stream (int fd, bool unformatted) /* Get the current length of the file. */ - fstat (fd, &statbuf); + if (fstat (fd, &statbuf) == -1) + { + s->st_dev = s->st_ino = -1; + s->file_length = 0; + if (errno == EBADF) + s->fd = -1; + raw_init (s); + return (stream *) s; + } s->st_dev = statbuf.st_dev; s->st_ino = statbuf.st_ino; |