[前][次][番号順一覧][スレッド一覧]

ruby-changes:38556

From: naruse <ko1@a...>
Date: Mon, 25 May 2015 11:35:41 +0900 (JST)
Subject: [ruby-changes:38556] naruse:r50637 (trunk): * win32/win32.c (setup_overlapped): seek to the file end only when

naruse	2015-05-25 11:35:31 +0900 (Mon, 25 May 2015)

  New Revision: 50637

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50637

  Log:
    * win32/win32.c (setup_overlapped): seek to the file end only when
      writing (mode:a), not reading (mode:a+, read).

  Modified files:
    trunk/ChangeLog
    trunk/win32/win32.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50636)
+++ ChangeLog	(revision 50637)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon May 25 11:27:14 2015  NARUSE, Yui  <naruse@r...>
+
+	* win32/win32.c (setup_overlapped): seek to the file end only when
+	  writing (mode:a), not reading (mode:a+, read).
+
 Mon May 25 00:27:37 2015  Benoit Daloze  <eregontp@g...>
 
 	* numeric.c (Numeric#negative?): [DOC] Fix call-seq.
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 50636)
+++ win32/win32.c	(revision 50637)
@@ -6469,12 +6469,16 @@ rb_w32_close(int fd) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L6469
 }
 
 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 si https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L6575
 
     /* 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, si https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L6705
 
     /* 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;
 	}

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]