From 88c5a50f9f1982b1ae8cc16350fbc9b60502d88a Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Fri, 29 Jul 2005 17:26:10 +0000 Subject: [PATCH] * fhandler_disk_file.cc (fhandler_base::pread): Don't move file offset pointer after I/O. (fhandler_base::pwrite): Ditto. --- winsup/cygwin/ChangeLog | 6 ++++++ winsup/cygwin/fhandler_disk_file.cc | 25 +++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 93eaaf721..0b477b571 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2005-07-29 Christopher Faylor + + * fhandler_disk_file.cc (fhandler_base::pread): Don't move file offset + pointer after I/O. + (fhandler_base::pwrite): Ditto. + 2005-07-29 Christopher Faylor * fhandler.h (fhandler_base::pread): Declare new function. diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 76fe9b393..3b3388c6f 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -987,12 +987,18 @@ fhandler_base::close_fs () ssize_t __stdcall fhandler_disk_file::pread (void *buf, size_t count, _off64_t offset) { - ssize_t res = lseek (offset, SEEK_SET); - if (res >= 0) + ssize_t res; + _off64_t curpos = lseek (0, SEEK_CUR); + if (curpos < 0 || lseek (offset, SEEK_SET) < 0) + res = -1; + else { size_t tmp_count = count; read (buf, tmp_count); - res = (ssize_t) tmp_count; + if (lseek (curpos, SEEK_SET) == 0) + res = (ssize_t) tmp_count; + else + res = -1; } debug_printf ("%d = pread (%p, %d, %d)\n", res, buf, count, offset); return res; @@ -1001,9 +1007,16 @@ fhandler_disk_file::pread (void *buf, size_t count, _off64_t offset) ssize_t __stdcall fhandler_disk_file::pwrite (void *buf, size_t count, _off64_t offset) { - ssize_t res = lseek (offset, SEEK_SET); - if (res >= 0) - res = write (buf, count); + int res; + _off64_t curpos = lseek (0, SEEK_CUR); + if (curpos < 0 || lseek (offset, SEEK_SET) < 0) + res = curpos; + else + { + res = (ssize_t) write (buf, count); + if (lseek (curpos, SEEK_SET) < 0) + res = -1; + } debug_printf ("%d = pwrite (%p, %d, %d)\n", res, buf, count, offset); return res; }