1*356694b0Swiz.\" $NetBSD: tcgetwinsize.3,v 1.2 2017/10/30 15:43:21 wiz Exp $ 2673e27deSkre.\" 3673e27deSkre.\" Copyright (c) 2017 The NetBSD Foundation, Inc. 4673e27deSkre.\" All rights reserved. 5673e27deSkre.\" 6673e27deSkre.\" Redistribution and use in source and binary forms, with or without 7673e27deSkre.\" modification, are permitted provided that the following conditions 8673e27deSkre.\" are met: 9673e27deSkre.\" 1. Redistributions of source code must retain the above copyright 10673e27deSkre.\" notice, this list of conditions and the following disclaimer. 11673e27deSkre.\" 2. Redistributions in binary form must reproduce the above copyright 12673e27deSkre.\" notice, this list of conditions and the following disclaimer in the 13673e27deSkre.\" documentation and/or other materials provided with the distribution. 14673e27deSkre.\" 15673e27deSkre.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16673e27deSkre.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17673e27deSkre.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18673e27deSkre.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19673e27deSkre.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20673e27deSkre.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21673e27deSkre.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22673e27deSkre.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23673e27deSkre.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24673e27deSkre.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25673e27deSkre.\" POSSIBILITY OF SUCH DAMAGE. 26673e27deSkre.\" 27673e27deSkre.Dd October 25, 2017 28673e27deSkre.Dt TCGETWINSIZE 3 29673e27deSkre.Os 30673e27deSkre.Sh NAME 31673e27deSkre.Nm tcgetwinsize , 32673e27deSkre.Nm tcsetwinsize 33673e27deSkre.Nd manipulate terminal window size 34673e27deSkre.Sh LIBRARY 35673e27deSkre.Lb libc 36673e27deSkre.Sh SYNOPSIS 37673e27deSkre.In termios.h 38673e27deSkre.Ft int 39673e27deSkre.Fn tcgetwinsize "int fd" "struct winsize *gws" 40673e27deSkre.Ft int 41673e27deSkre.Fn tcsetwinsize "int fd" "const struct winsize *sws" 42673e27deSkre.Sh DESCRIPTION 43673e27deSkreThe 44673e27deSkre.Nm tcgetwinsize 45673e27deSkrefunction fills in the 46673e27deSkre.Ic winsize 47673e27deSkrestructure pointed to by 48673e27deSkre.Fa gws 49673e27deSkrewith values that represent the size of the 50673e27deSkreterminal window for which 51673e27deSkre.Fa fd 52673e27deSkreprovides an open file descriptor. 53673e27deSkreIf no error occurs 54673e27deSkre.Fn tcgetwinsize 55673e27deSkrereturns zero (0). 56673e27deSkre.Pp 57673e27deSkreThe 58673e27deSkre.Nm tcsetwinsize 59673e27deSkrefunction sets the terminal window size, 60673e27deSkrefor the terminal referenced by 61673e27deSkre.Fa fd , 62673e27deSkreto the sizes from the 63673e27deSkre.Ic winsize 64673e27deSkrestructure pointed to by 65673e27deSkre.Fa sws . 66673e27deSkreIf no error occurs 67673e27deSkre.Fn tcsetwinsize 68673e27deSkrereturns zero (0). 69673e27deSkre.Pp 70673e27deSkreThe 71673e27deSkre.Ic winsize 72673e27deSkrestructure, defined in 73673e27deSkre.In termios.h , 74673e27deSkrecontains (at least) the following four fields 75673e27deSkre.Bd -literal 76673e27deSkre unsigned short ws_row; /* Number of rows, in characters */ 77673e27deSkre unsigned short ws_col; /* Number of columns, in characters */ 78673e27deSkre unsigned short ws_xpixel; /* Width, in pixels */ 79673e27deSkre unsigned short ws_ypixel; /* Height, in pixels */ 80673e27deSkre.Ed 81673e27deSkre.Pp 82673e27deSkreIf the actual window size of the controlling terminal 83673e27deSkreof a process changes, the process is sent a 84673e27deSkre.Dv SIGWINCH 85673e27deSkresignal. 86673e27deSkreSee 87673e27deSkre.Xr signal 7 . 88673e27deSkreNote simply changing the sizes using 89673e27deSkre.Fn tcsetwinsize 90673e27deSkredoes not necessarily change the actual window size, 91673e27deSkreand if not, will not generate a 92673e27deSkre.Dv SIGWINCH . 93673e27deSkre.Sh ERRORS 94673e27deSkreIf an error occurs, 95673e27deSkre.Fn tcgetwinsize 96673e27deSkreand 97673e27deSkre.Fn tcsetwinsize 98*356694b0Swizreturn \-1 and cause the global variable 99673e27deSkre.Va errno 100673e27deSkreto be set to indicate the error. 101673e27deSkreCommon errors are as follows: 102673e27deSkre.Bl -tag -width Er 103673e27deSkre.It Bq Er EBADF 104673e27deSkreThe 105673e27deSkre.Fa fd 106673e27deSkreargument to 107673e27deSkre.Fn tcgetwinsize 108673e27deSkreor 109673e27deSkre.Fn tcsetwinsize 110673e27deSkreis not a valid file descriptor. 111673e27deSkre.It Bq Er EFAULT 112673e27deSkreThe 113673e27deSkre.Fa gws 114673e27deSkreargument to 115673e27deSkre.Fn tcgetwinsize 116673e27deSkredoes not point to a suitable location 117673e27deSkreinto which to store the resulting 118673e27deSkre.Ic winsize 119673e27deSkrestructure, 120673e27deSkreor the 121673e27deSkre.Fa sws 122673e27deSkreargument to 123673e27deSkre.Fn tcsetwinsize 124673e27deSkredoes not refer to a suitable location 125673e27deSkrefrom which the 126673e27deSkre.Ic winsize 127673e27deSkrestructure can be obtained. 128673e27deSkre.It Bq Er EINVAL 129673e27deSkreThe values passed in the 130673e27deSkre.Ar sws 131673e27deSkre.Ic winsize 132673e27deSkrestructure to 133673e27deSkre.Fn tcsetwinsize 134673e27deSkrerepresent an attempt to set the window size to an invalid state. 135673e27deSkre.It Bq Er ENOTTY 136673e27deSkreThe 137673e27deSkre.Fa fd 138673e27deSkreargument to 139673e27deSkre.Fn tcgetwinsize 140673e27deSkreor 141673e27deSkre.Fn tcsetwinsize 142673e27deSkredoes not represent a terminal device capable 143673e27deSkreof remembering a window size. 144*356694b0Swiz.El 145673e27deSkre.Sh SEE ALSO 146673e27deSkre.Xr stty 1 , 147673e27deSkre.Xr pty 4 , 148*356694b0Swiz.Xr termios 4 , 149673e27deSkre.Xr tty 4 , 150673e27deSkre.Xr signal 7 151673e27deSkre.Sh STANDARDS 152673e27deSkreThe 153673e27deSkre.Nm tcgetwinsize 154673e27deSkreand 155673e27deSkre.Nm tcsetwinsize 156673e27deSkrefunctions will conform to 157673e27deSkre.St -p1003.1 158673e27deSkreissue 8, when it is published. 159673e27deSkre.Pp 160673e27deSkreThe 161673e27deSkre.Ic ws_xpixel 162673e27deSkreand 163673e27deSkre.Ic ws_ypixel 164673e27deSkrefields are extensions to the standard. 165673e27deSkre.Pp 166673e27deSkreThe standard only requires pseudo-terminals 167673e27deSkre.Pq Xr pty 4 168673e27deSkreto support these operations. 169673e27deSkreIn 170673e27deSkre.Nx 171673e27deSkreall terminal devices can set and recall a window size, 172673e27deSkreregardless of whether any actual window exists. 173673e27deSkre.Sh HISTORY 174673e27deSkreThe 175673e27deSkre.Fn tcgetwinsize 176673e27deSkreand 177673e27deSkre.Fn tcsetwinsize 178673e27deSkrefunctions were added in 179673e27deSkre.Nx 8.0 180673e27deSkreafter specification by POSIX 181673e27deSkreas more portable alternatives to ancient 182673e27deSkre.Ic ioctl 183673e27deSkreoperations from 184673e27deSkre.Bx 4.3 . 185673e27deSkre.Sh CAVEATS 186673e27deSkreIt is unspecified whether calling the 187673e27deSkre.Nm tcsetwinsize 188673e27deSkrefunction causes the underlying terminal window to be resized. 189673e27deSkreNor is it specified whether altering the relationship between 190673e27deSkrethe character fields (ws_row and ws_col) and the pixel fields 191673e27deSkre(ws_xpixel and ws_ypixel) causes the font size to change, or 192673e27deSkrewhether the application is required to maintain any specific 193673e27deSkrerelationship between these fields. 194673e27deSkreIn general, the 195673e27deSkre.Nm tcsetwinsize 196673e27deSkrefunction is best avoided except by applications responsible 197673e27deSkrefor actually implementing terminal windows. 198673e27deSkre.Pp 199673e27deSkreAs the 200673e27deSkre.Ic winsize 201673e27deSkrestructure may have more fields than documented, applications 202673e27deSkreplanning to call 203673e27deSkre.Fn tcsetwinsize 204673e27deSkreshould call 205673e27deSkre.Fn tcgetwinsize 206673e27deSkrefirst with the same 207673e27deSkre.Ar fd 208673e27deSkreparameter, and use the result obtained in 209673e27deSkre.Ar *gws 210673e27deSkreto initialize the 211673e27deSkre.Ic winsize 212673e27deSkrestructure to be used (after altering fields that are to be changed) 213673e27deSkreas the 214673e27deSkre.Ar sws 215673e27deSkreoperand of 216673e27deSkre.Nm tcsetwinsize . 217