diff options
author | jb <jb@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-06-11 10:19:49 +0000 |
---|---|---|
committer | jb <jb@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-06-11 10:19:49 +0000 |
commit | 9bfd25a7df9b8143fda651de2a4f9622cbae595c (patch) | |
tree | f8dc4399ed8813242826269d056cc2f2039b1304 /libgfortran | |
parent | d1c8b77855f3ae59f847a2740f528eeb308dce09 (diff) | |
download | gcc-9bfd25a7df9b8143fda651de2a4f9622cbae595c.tar.gz |
Figure out whether a file is seekable with lseek()
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@174946 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran')
-rw-r--r-- | libgfortran/ChangeLog | 5 | ||||
-rw-r--r-- | libgfortran/io/unix.c | 12 |
2 files changed, 11 insertions, 6 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index bcd62f52c32..d54878b189f 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,8 @@ +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(). + 2011-06-10 Daniel Carrera <dcarrera@gmail.com> * caf/mpi.c (_gfortran_caf_sync_all, diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index c257766d653..e3ae6072290 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -952,15 +952,15 @@ fd_to_stream (int fd) if (S_ISREG (statbuf.st_mode)) s->file_length = statbuf.st_size; - else if (S_ISBLK (statbuf.st_mode)) + else { - /* Hopefully more portable than ioctl(fd, BLKGETSIZE64, &size)? */ - gfc_offset cur = lseek (fd, 0, SEEK_CUR); + /* Some character special files are seekable but most are not, + so figure it out by trying to seek. On Linux, /dev/null is + an example of such a special file. */ s->file_length = lseek (fd, 0, SEEK_END); - lseek (fd, cur, SEEK_SET); + if (s->file_length > 0) + lseek (fd, 0, SEEK_SET); } - else - s->file_length = -1; if (!(S_ISREG (statbuf.st_mode) || S_ISBLK (statbuf.st_mode)) || options.all_unbuffered |