summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--ext/io/console/console.c18
-rw-r--r--io.c2
3 files changed, 20 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 470a60d0f6..d13ca87a74 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Sat Mar 21 15:01:26 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/io/console/console.c (console_set_winsize): use handle for
+ writing. GetConsoleScreenBufferInfo seems failing on a handle
+ for reading.
+
+ * io.c: [DOC] update the example of IO#winsize to use $stdout
+ instead of $stdin, which does not work on Windows. a patch by
+ Jan Lelis <mail AT janlelis.de> at [ruby-core:68574].
+ [Bug #10986]
+
Fri Mar 20 18:41:03 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* proc.c (respond_to_missing_p): check if the receiver responds to
diff --git a/ext/io/console/console.c b/ext/io/console/console.c
index b360090b66..c5d61eb39d 100644
--- a/ext/io/console/console.c
+++ b/ext/io/console/console.c
@@ -525,16 +525,14 @@ console_set_winsize(VALUE io, VALUE size)
int newrow, newcol;
#endif
VALUE row, col, xpixel, ypixel;
-#if defined TIOCSWINSZ
int fd;
-#endif
GetOpenFile(io, fptr);
size = rb_Array(size);
rb_scan_args((int)RARRAY_LEN(size), RARRAY_PTR(size), "22",
&row, &col, &xpixel, &ypixel);
-#if defined TIOCSWINSZ
fd = GetWriteFD(fptr);
+#if defined TIOCSWINSZ
ws.ws_row = ws.ws_col = ws.ws_xpixel = ws.ws_ypixel = 0;
#define SET(m) ws.ws_##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m)
SET(row);
@@ -544,24 +542,24 @@ console_set_winsize(VALUE io, VALUE size)
#undef SET
if (!setwinsize(fd, &ws)) rb_sys_fail(0);
#elif defined _WIN32
- wh = (HANDLE)rb_w32_get_osfhandle(GetReadFD(fptr));
+ wh = (HANDLE)rb_w32_get_osfhandle(fd);
newrow = (SHORT)NUM2UINT(row);
newcol = (SHORT)NUM2UINT(col);
- if (!getwinsize(GetReadFD(fptr), &ws)) {
- rb_sys_fail("GetConsoleScreenBufferInfo");
+ if (!GetConsoleScreenBufferInfo(wh, &ws)) {
+ rb_syserr_fail(LAST_ERROR, "GetConsoleScreenBufferInfo");
}
if ((ws.dwSize.X < newcol && (ws.dwSize.X = newcol, 1)) ||
(ws.dwSize.Y < newrow && (ws.dwSize.Y = newrow, 1))) {
- if (!(SetConsoleScreenBufferSize(wh, ws.dwSize) || SET_LAST_ERROR)) {
- rb_sys_fail("SetConsoleScreenBufferInfo");
+ if (!SetConsoleScreenBufferSize(wh, ws.dwSize)) {
+ rb_syserr_fail(LAST_ERROR, "SetConsoleScreenBufferInfo");
}
}
ws.srWindow.Left = 0;
ws.srWindow.Top = 0;
ws.srWindow.Right = newcol;
ws.srWindow.Bottom = newrow;
- if (!(SetConsoleWindowInfo(wh, FALSE, &ws.srWindow) || SET_LAST_ERROR)) {
- rb_sys_fail("SetConsoleWindowInfo");
+ if (!SetConsoleWindowInfo(wh, FALSE, &ws.srWindow)) {
+ rb_syserr_fail(LAST_ERROR, "SetConsoleWindowInfo");
}
#endif
return io;
diff --git a/io.c b/io.c
index 3ac591a113..1d3677ad62 100644
--- a/io.c
+++ b/io.c
@@ -12078,7 +12078,7 @@ rb_readwrite_sys_fail(int writable, const char *mesg)
* Example:
*
* require 'io/console'
- * rows, columns = $stdin.winsize
+ * rows, columns = $stdout.winsize
* puts "Your screen is #{columns} wide and #{rows} tall"
*/