public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Janne Blomqvist <blomqvist.janne@gmail.com>
To: Fortran List <fortran@gcc.gnu.org>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [Patch, libfortran, committed] Use lseek() to figure out if a file is seekable
Date: Sat, 11 Jun 2011 11:16:00 -0000	[thread overview]
Message-ID: <BANLkTi=qdhB72XqzvXsxhHGq7bi46zUKjA@mail.gmail.com> (raw)

Hi,

currently we try to figure out whether a fd is seekable by looking at
the mode returned by fstat(). Turns out this is not enough, as there
are some character special files that are seekable. Thus, change the
logic to try an lseek().

Committed as obvious.

Index: ChangeLog
===================================================================
--- ChangeLog   (revision 174945)
+++ ChangeLog   (working copy)
@@ -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,
Index: io/unix.c
===================================================================
--- io/unix.c   (revision 174945)
+++ io/unix.c   (working copy)
@@ -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


-- 
Janne Blomqvist

                 reply	other threads:[~2011-06-11 10:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='BANLkTi=qdhB72XqzvXsxhHGq7bi46zUKjA@mail.gmail.com' \
    --to=blomqvist.janne@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).