aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJanne Blomqvist <jb@gcc.gnu.org>2011-06-11 13:52:18 +0300
committerJanne Blomqvist <jb@gcc.gnu.org>2011-06-11 13:52:18 +0300
commit09ad57ec8fa24e40b2364d1d67218c65acedaf4d (patch)
tree52efaae296e32e1cb15ce5aac3ccf45942fdb8fe
parent5ea0705af7ff3e31d669808cc1c39b673b7122f8 (diff)
downloadgcc-09ad57ec8fa24e40b2364d1d67218c65acedaf4d.zip
gcc-09ad57ec8fa24e40b2364d1d67218c65acedaf4d.tar.gz
gcc-09ad57ec8fa24e40b2364d1d67218c65acedaf4d.tar.bz2
Return error when trying to seek a non-seekable buffered file
From-SVN: r174947
-rw-r--r--libgfortran/ChangeLog5
-rw-r--r--libgfortran/io/unix.c7
2 files changed, 11 insertions, 1 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index d54878b..9d53375 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,5 +1,10 @@
2011-06-11 Janne Blomqvist <jb@gcc.gnu.org>
+ * io/unix.c (buf_seek): Return error if file is not seekable.
+ (buf_tell): Call buf_seek.
+
+2011-06-11 Janne Blomqvist <jb@gcc.gnu.org>
+
* io/unix.c (fd_to_stream): Figure out if a fd is seekable by
trying lseek().
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c
index e3ae607..25cb559 100644
--- a/libgfortran/io/unix.c
+++ b/libgfortran/io/unix.c
@@ -560,6 +560,11 @@ buf_write (unix_stream * s, const void * buf, ssize_t nbyte)
static gfc_offset
buf_seek (unix_stream * s, gfc_offset offset, int whence)
{
+ if (s->file_length == -1)
+ {
+ errno = ESPIPE;
+ return -1;
+ }
switch (whence)
{
case SEEK_SET:
@@ -585,7 +590,7 @@ buf_seek (unix_stream * s, gfc_offset offset, int whence)
static gfc_offset
buf_tell (unix_stream * s)
{
- return s->logical_offset;
+ return buf_seek (s, 0, SEEK_CUR);
}
static int