]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Don't update the position flag for non-seekable files, check for stell() error.
authorJanne Blomqvist <jb@gcc.gnu.org>
Mon, 2 Aug 2010 06:22:23 +0000 (09:22 +0300)
committerJanne Blomqvist <jb@gcc.gnu.org>
Mon, 2 Aug 2010 06:22:23 +0000 (09:22 +0300)
From-SVN: r162810

libgfortran/ChangeLog
libgfortran/io/unit.c

index f11ede973f076cd539f99d265877dd3bb2c2755a..700cb60e7868a323fe0e58cf84a01767574a40ff 100644 (file)
@@ -1,3 +1,8 @@
+2010-08-02  Janne Blomqvist  <jb@gcc.gnu.org>
+
+       * io/unit.c (update_position): Don't update the position flag for
+       non-seekable files, check for stell() error.
+
 2010-08-01  Janne Blomqvist  <jb@gcc.gnu.org>
 
         * io/unix.c (file_exists): Use access(2) instead of stat(2) to
index a0018dbb4f7280fc95df24329cf8d53f168a2146..1d52217263552f2cf89726f09a767e20c1dc6fbc 100644 (file)
@@ -714,12 +714,19 @@ close_units (void)
 void
 update_position (gfc_unit *u)
 {
-  if (stell (u->s) == 0)
-    u->flags.position = POSITION_REWIND;
-  else if (file_length (u->s) == stell (u->s))
-    u->flags.position = POSITION_APPEND;
-  else
-    u->flags.position = POSITION_ASIS;
+  /* If unit is not seekable, this makes no sense (and the standard is
+     silent on this matter), and thus we don't change the position for
+     a non-seekable file.  */
+  if (is_seekable (u->s))
+    {
+      gfc_offset cur = stell (u->s);
+      if (cur == 0)
+       u->flags.position = POSITION_REWIND;
+      else if (cur != -1 && (file_length (u->s) == cur))
+       u->flags.position = POSITION_APPEND;
+      else
+       u->flags.position = POSITION_ASIS;
+    }
 }