Skip to content

Commit 93aa81b

Browse files
committed
FEAT: using more robust posix implementation of the QUERY on console port
1 parent a9522e0 commit 93aa81b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/os/posix/dev-stdio.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,28 @@ static void Close_Stdio(void)
272272
**
273273
***********************************************************************/
274274
{
275+
#ifdef TIOCGWINSZ
275276
struct winsize w;
276-
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
277+
if (ioctl(Std_Out, TIOCGWINSZ, &w) != 0) {
278+
req->error = errno;
279+
return DR_ERROR;
280+
}
277281
req->console.window_rows =
278282
req->console.buffer_rows = w.ws_row;
279283
req->console.window_cols =
280284
req->console.buffer_cols = w.ws_col;
285+
#else
286+
#ifdef WIOCGETD
287+
struct uwdata w;
288+
if (ioctl(Std_Out, WIOCGETD, &w) != 0) {
289+
req->error = errno;
290+
return DR_ERROR;
291+
}
292+
req->console.window_rows =
293+
req->console.buffer_rows = w.uw_height / w.uw_vs;
294+
req->console.window_cols =
295+
req->console.buffer_cols = w.uw_width / w.uw_hs;
296+
#endif
281297
return DR_DONE;
282298
}
283299

src/tests/units/port-test.r3

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ Rebol [
2424
--test-- "query input port"
2525
--assert port? system/ports/input
2626
--assert object? console-info: query system/ports/input
27-
?? console-info
27+
--assert pair? try [console-info/window-size]
28+
;?? console-info
2829
===end-group===
2930

3031
~~~end-file~~~

0 commit comments

Comments
 (0)