From d4bafbb45f261a69cc3bc4552050893400ce4a1d Mon Sep 17 00:00:00 2001 From: naruse Date: Mon, 25 May 2015 02:35:31 +0000 Subject: * 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/trunk@50637 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- win32/win32.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'win32/win32.c') diff --git a/win32/win32.c b/win32/win32.c index d84a913254..b23e9af24d 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -6469,12 +6469,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) @@ -6571,7 +6575,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)) { rb_acrt_lowio_unlock_fh(fd); return -1; } @@ -6701,7 +6705,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)) { rb_acrt_lowio_unlock_fh(fd); return -1; } -- cgit v1.2.3