when to use ioctl with TIOCGWINSZ

Doug Gwyn gwyn at smoke.BRL.MIL
Mon Jan 15 04:45:04 AEST 1990


In article <22086 at adm.BRL.MIL> Leisner.Henr at xerox.com (Marty) writes:
-This code sequence seems to cause problems on some remote terminals (via
-TCP/IP or XNS).  It works on rlogin between suns.  It doesn't work with
-telnet.  It doesn't work on rlogin between a non-sun and a sun.

Window size information is not passed at all as part of TELNET protocol.
4.2BSD and 4.3BSD passed window size information differently for rlogin.

-        /* get the window size, one way or another. */
-#ifdef TIOCGWINSZ
-        LINES = COLS = 0;
-        if (ioctl(2, TIOCGWINSZ, &size) >= 0)
-        {
-                LINES = size.ws_row;
-                COLS = size.ws_col;
-        }
-#else
-        LINES = tgetnum("li");
-        COLS = tgetnum("co");
-#endif
-Essentially, when there's a problem(?), ioctl isn't returning an error, and
-LINES and COLS get set to 0.

The code is in error to assume that a successful ioctl means that the
ws_row and ws_col data describes the window.  As you have discovered,
they will be 0 until properly set to the window dimensions.  The code
should test for that common case and use the LINES and COLUMNS
environment variables if the ioctl fails, and if the environment
variables aren't set to reasonable values it should prefer the termcap
li and co capabilities.

-TIOCGWINSZ returns the terminal driver's notion of the size.  I guess the
-driver got the wrong notion (actually how can the driver know what size a
-remote terminal is?).

The information is set by some TIOCSWINSZ, for example when the rlogin
daemon successfully obtains the window information from the remote system.



More information about the Comp.unix.wizards mailing list