]> sourceware.org Git - newlib-cygwin.git/commitdiff
* fhandler_floppy.cc (fhandler_dev_floppy::lseek): Don't invalidate
authorCorinna Vinschen <corinna@vinschen.de>
Tue, 22 May 2007 07:16:19 +0000 (07:16 +0000)
committerCorinna Vinschen <corinna@vinschen.de>
Tue, 22 May 2007 07:16:19 +0000 (07:16 +0000)
devbuf if new position is within buffered range.

winsup/cygwin/ChangeLog
winsup/cygwin/fhandler_floppy.cc

index 1a8de02ff32798d7c3e247b8bb440bd58e2e2c5c..e9047b288550018cbaae73663cec3dc6c467e7de 100644 (file)
@@ -1,3 +1,8 @@
+2007-05-21  Christian Franke <franke@computer.org>
+
+       * fhandler_floppy.cc (fhandler_dev_floppy::lseek): Don't invalidate
+       devbuf if new position is within buffered range.
+
 2007-05-21  Eric Blake  <ebb9@byu.net>
 
        * include/search.h (hsearch_r): Provide declaration.
index ee8d56b5724f440ad8fa039bb9819923922a32d2..bcd0c7df6719a0ddd421f939d288a7b0c0b17043 100644 (file)
@@ -410,6 +410,7 @@ fhandler_dev_floppy::lseek (_off64_t offset, int whence)
 {
   char buf[bytes_per_sector];
   _off64_t lloffset = offset;
+  _off64_t current_pos = (_off64_t) -1;
   LARGE_INTEGER sector_aligned_offset;
   size_t bytes_left;
 
@@ -420,7 +421,8 @@ fhandler_dev_floppy::lseek (_off64_t offset, int whence)
     }
   else if (whence == SEEK_CUR)
     {
-      lloffset += get_current_position () - (devbufend - devbufstart);
+      current_pos = get_current_position ();
+      lloffset += current_pos - (devbufend - devbufstart);
       whence = SEEK_SET;
     }
 
@@ -430,6 +432,18 @@ fhandler_dev_floppy::lseek (_off64_t offset, int whence)
       return -1;
     }
 
+  /* If new position is in buffered range, adjust buffer and return */
+  if (devbufstart < devbufend)
+    {
+      if (current_pos == (_off64_t) -1)
+       current_pos = get_current_position ();
+      if (current_pos - devbufend <= lloffset && lloffset <= current_pos)
+       {
+         devbufstart = devbufend - (current_pos - lloffset);
+         return lloffset;
+       }
+    }
+
   sector_aligned_offset.QuadPart = (lloffset / bytes_per_sector)
                                   * bytes_per_sector;
   bytes_left = lloffset - sector_aligned_offset.QuadPart;
This page took 0.033355 seconds and 5 git commands to generate.