diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2011-06-11 13:19:49 +0300 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2011-06-11 13:19:49 +0300 |
commit | 5ea0705af7ff3e31d669808cc1c39b673b7122f8 (patch) | |
tree | f8dc4399ed8813242826269d056cc2f2039b1304 /libgfortran/io | |
parent | ba94c7af45cf628c815208b4a961138ef279fe1a (diff) | |
download | gcc-5ea0705af7ff3e31d669808cc1c39b673b7122f8.zip gcc-5ea0705af7ff3e31d669808cc1c39b673b7122f8.tar.gz gcc-5ea0705af7ff3e31d669808cc1c39b673b7122f8.tar.bz2 |
Figure out whether a file is seekable with lseek()
From-SVN: r174946
Diffstat (limited to 'libgfortran/io')
-rw-r--r-- | libgfortran/io/unix.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index c257766..e3ae607 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 |