OSDN Git Service

2006-02-24 Jerry DeLisle <jvdelisle@gcc.gnu.org>
authorjvdelisle <jvdelisle@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 24 Feb 2006 18:16:25 +0000 (18:16 +0000)
committerjvdelisle <jvdelisle@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 24 Feb 2006 18:16:25 +0000 (18:16 +0000)
PR libgfortran/26423
* io/unix.c (fd_seek): Revert change from 25949.
(fd_read): Same.
(fd_write): Same.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@111420 138bc75d-0d04-0410-961f-82ee72b054a4

libgfortran/ChangeLog
libgfortran/io/unix.c

index f56bf57..a570af4 100644 (file)
@@ -1,3 +1,10 @@
+2006-02-24  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/26423
+       * io/unix.c (fd_seek): Revert change from 25949.
+       (fd_read): Same.
+       (fd_write): Same.
+
 2006-02-19  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
 
        * io/open.c (edit_modes): Correct abusive copy-pasting.
index 40ad2d8..1293b24 100644 (file)
@@ -562,9 +562,15 @@ fd_sfree (unix_stream * s)
 static try
 fd_seek (unix_stream * s, gfc_offset offset)
 {
-  s->logical_offset = offset;
+  if (s->physical_offset == offset) /* Are we lucky and avoid syscall?  */
+    {
+      s->logical_offset = offset;
+      return SUCCESS;
+    }
 
-  return SUCCESS;
+  s->physical_offset = s->logical_offset = offset;
+
+  return (lseek (s->fd, offset, SEEK_SET) < 0) ? FAILURE : SUCCESS;
 }
 
 
@@ -666,8 +672,7 @@ fd_read (unix_stream * s, void * buf, size_t * nbytes)
       return errno;
     }
 
-  if (is_seekable ((stream *) s) && s->physical_offset != s->logical_offset 
-      && lseek (s->fd, s->logical_offset, SEEK_SET) < 0)
+  if (is_seekable ((stream *) s) && fd_seek (s, s->logical_offset) == FAILURE)
     {
       *nbytes = 0;
       return errno;
@@ -715,8 +720,7 @@ fd_write (unix_stream * s, const void * buf, size_t * nbytes)
       return errno;
     }
 
-  if (is_seekable ((stream *) s) && s->physical_offset != s->logical_offset
-      && lseek (s->fd, s->logical_offset, SEEK_SET) < 0)
+  if (is_seekable ((stream *) s) && fd_seek (s, s->logical_offset) == FAILURE)
     {
       *nbytes = 0;
       return errno;