Issue #5714 has been updated by Hiroshi Shirosaki.

File set_binmode_fix_r34120.patch added

I updated the patch while waiting for the response.

Cleanups
* remove unnecessary parentheses of `fptr`
* use return value of setmode() which returns the previous translation mode if successful 
http://msdn.microsoft.com/en-us/library/tw4k6df8.aspx


Test results of trunk r34120 mingw32 on Windows7 64bit

"make test" passed.
test-all failures and errors were as below. Result is same as before patch.

test_race_exception(TestRequire)
test_generate_bin_bindir_with_user_install_warning(TestGemInstaller)
test_s_open_error(TestGDBM)
test_s_open_create_new(TestGDBM)
test_thread_timer_and_interrupt(TestThreadGroup)  # This test was hung-up.
test_constants(OpenSSL::TestConfig)
test_reorganize(TestGDBM)
test_filename_as_bytes_extutf8(TestDir_M17N)
test_filename_extutf8_inteucjp_unrepresentable(TestDir_M17N)

----------------------------------------
Bug #5714: Unexpected error of STDIN#read with non-ascii input on Windows XP
https://bugs.ruby-lang.org/issues/5714

Author: Heesob Park
Status: Closed
Priority: Normal
Assignee: Usaku NAKAMURA
Category: build
Target version: 
ruby -v: -


When the input contains non-ascii character, STDIN#read raised Permission denied or Invalid argument error with MSVC compiled version on Windows XP.

	C:\work>ruby -ve 'p STDIN.read(5)'
	ruby 2.0.0dev (2011-12-05 trunk 33955) [i386-mswin32_100]
	abcd
	-e:1:in `read': Permission denied - <STDIN> (Errno::EACCES)
		from -e:1:in `<main>'

	C:\>irb
	irb(main):001:0> STDIN.read(5)
	abcd
	Errno::EINVAL: Invalid argument - <STDIN>
		from (irb):1:in `read'
		from (irb):1
		from c:/usr/bin/irb.bat:19:in `<main>'

If the input is ascii only, STDIN.read works fine.

	C:\work>ruby -ve 'p STDIN.read(5)'
	ruby 2.0.0dev (2011-12-05 trunk 33955) [i386-mswin32_100]
	abcdefg
	"abcde"

	C:\>irb
	irb(main):001:0> STDIN.read(5)
	abcdefg
	=> "abcde"

It is odd but the Mingw compiled version works fine.

	C:\work>ruby -ve 'p STDIN.read(5)'
	ruby 2.0.0dev (2011-12-05 trunk 33955) [i386-mingw32]
	abcde
	"\xC7\xD1\xB1\xDBabc"

And Ruby 1.9.3p0 works fine.
	
	C:\>ruby -ve 'p STDIN.read(5)'
	ruby 1.9.3p0 (2011-10-30 revision 33570) [i386-mswin32_100]
	abcd
	"\xC7\xD1\xB1\xDBabc"



-- 
http://redmine.ruby-lang.org