Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.unix.wizards Subject: Re: when to use ioctl with TIOCGWINSZ Message-ID: <11951@smoke.BRL.MIL> Date: 14 Jan 90 17:45:04 GMT References: <22086@adm.BRL.MIL> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 37 In article <22086@adm.BRL.MIL> Leisner.Henr@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.