Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2005-07-29 21:26:10 +0400
committerChristopher Faylor <me@cgf.cx>2005-07-29 21:26:10 +0400
commit88c5a50f9f1982b1ae8cc16350fbc9b60502d88a (patch)
treea67eef3ba9f12719789e50caa300604dd2dab75f /winsup/cygwin/fhandler_disk_file.cc
parentca4870999679e833bfaa85dacbea74b5cbb49ff4 (diff)
* fhandler_disk_file.cc (fhandler_base::pread): Don't move file offset pointer
after I/O. (fhandler_base::pwrite): Ditto.
Diffstat (limited to 'winsup/cygwin/fhandler_disk_file.cc')
-rw-r--r--winsup/cygwin/fhandler_disk_file.cc25
1 files changed, 19 insertions, 6 deletions
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;
}