summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-11 16:14:45 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-11 16:14:45 +0000
commit61ed7934b674893f79f5bf7e03619ab93efe52e2 (patch)
treeba9ad0fabf32bb820bb9816e646ca272311b8e55 /win32
parentb9ae7528dd0fc3b69cedc37a390e7d82accddeda (diff)
merge revision(s) 50637: [Backport #11172]
* win32/win32.c (setup_overlapped): seek to the file end only when writing (mode:a), not reading (mode:a+, read). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@50836 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/win32/win32.c b/win32/win32.c
index b7d7e32935..fc2c99edf1 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -6318,12 +6318,16 @@ rb_w32_close(int fd)
}
static int
-setup_overlapped(OVERLAPPED *ol, int fd)
+setup_overlapped(OVERLAPPED *ol, int fd, int iswrite)
{
memset(ol, 0, sizeof(*ol));
if (!(_osfile(fd) & (FDEV | FPIPE))) {
LONG high = 0;
- DWORD method = _osfile(fd) & FAPPEND ? FILE_END : FILE_CURRENT;
+ /* On mode:a, it can write only FILE_END.
+ * On mode:a+, though it can write only FILE_END,
+ * it can read from everywhere.
+ */
+ DWORD method = ((_osfile(fd) & FAPPEND) && iswrite) ? FILE_END : FILE_CURRENT;
DWORD low = SetFilePointer((HANDLE)_osfhnd(fd), 0, &high, method);
#ifndef INVALID_SET_FILE_POINTER
#define INVALID_SET_FILE_POINTER ((DWORD)-1)
@@ -6420,7 +6424,7 @@ rb_w32_read(int fd, void *buf, size_t size)
/* if have cancel_io, use Overlapped I/O */
if (cancel_io) {
- if (setup_overlapped(&ol, fd)) {
+ if (setup_overlapped(&ol, fd, FALSE)) {
MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock));
return -1;
}
@@ -6550,7 +6554,7 @@ rb_w32_write(int fd, const void *buf, size_t size)
/* if have cancel_io, use Overlapped I/O */
if (cancel_io) {
- if (setup_overlapped(&ol, fd)) {
+ if (setup_overlapped(&ol, fd, TRUE)) {
MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock));
return -1;
}