From: Heesob Park Date: 2011-12-08T10:22:10+09:00 Subject: [ruby-core:41536] Re: [ruby-trunk - Bug #5714] Unexpected error of STDIN#read with non-ascii input on Windows XP Hi, 2011/12/7 Hiroshi Shirosaki > > > > > - �� ��if (_osfile(fd) & FTEXT) { > > + �� ��isconsole = is_console(_osfhnd(fd)); > > + �� ��if (!isconsole && (_osfile(fd) & FTEXT)) { > > �� �� �� ��return _read(fd, buf, size); > > �� �� } > > > > I intended STDIN doesn't use text mode at #5562 patch. So STDIN > doesn't need to use _read(). > I thought (_osfile(fd) & FTEXT) should be false in the case of STDIN. > I found that the initial value of _osfile(STDIN) is 0xC1 and same for _osfile(STDOUT) and _osfile(STDERR). The value 0xC1 means (FTEXT | FDEV | FOPEN). Here is another patch for diff --git a/win32.c b/win32.c.new index 67a392e..db9e222 100644 --- a/win32.c +++ b/win32.c.new @@ -2259,12 +2259,21 @@ init_stdhandle(void) if (fileno(stdin) < 0) { stdin->_file = open_null(0); } + else { + setmode(fileno(stdin), O_BINARY); // _osfile(fileno(stdin)) &= ~FTEXT; + } if (fileno(stdout) < 0) { stdout->_file = open_null(1); } + else { + setmode(fileno(stdout), O_BINARY); // _osfile(fileno(stdout)) &= ~FTEXT; + } if (fileno(stderr) < 0) { stderr->_file = open_null(2); } + else { + setmode(fileno(stderr), O_BINARY); // _osfile(fileno(stderr)) &= ~FTEXT; + } if (nullfd >= 0 && !keep) close(nullfd); setvbuf(stderr, NULL, _IONBF, 0); } Regards, Park Heesob