public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Janne Blomqvist <blomqvist.janne@gmail.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>,
	Fortran List <fortran@gcc.gnu.org>
Subject: [Patch, libfortran, committed] Return error when trying to seek a non-seekable buffered file
Date: Sat, 11 Jun 2011 11:59:00 -0000	[thread overview]
Message-ID: <BANLkTinGbAsE7EwZPT-BD4KCOhnaELE9_g@mail.gmail.com> (raw)

Hi,

In libgfortran, buffered and unbuffered IO should work the same except
for the buffering. For the unbuffered IO, seek and tell operations
reduce to calls to lseek(). Thus, if the file is not seekable, they
return -1 and set errno. Or strictly speaking, POSIX says that lseek()
on a non-seekable file is implementation-dependent, but AFAIK most
implementations return error. The attached patch makes buffered IO
behave the same.

Regtested on x86_64-unknown-linux-gnu, committed as obvious.


Index: ChangeLog
===================================================================
--- ChangeLog   (revision 174946)
+++ ChangeLog   (working copy)
@@ -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().

Index: io/unix.c
===================================================================
--- io/unix.c   (revision 174946)
+++ io/unix.c   (working copy)
@@ -560,6 +560,11 @@ buf_write (unix_stream * s, const void *
 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 of
 static gfc_offset
 buf_tell (unix_stream * s)
 {
-  return s->logical_offset;
+  return buf_seek (s, 0, SEEK_CUR);
 }

 static int


-- 
Janne Blomqvist

                 reply	other threads:[~2011-06-11 10:57 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=BANLkTinGbAsE7EwZPT-BD4KCOhnaELE9_g@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).