Index: lib/libc/gen/Makefile.inc =================================================================== --- lib/libc/gen/Makefile.inc +++ lib/libc/gen/Makefile.inc @@ -306,6 +306,7 @@ tcsetattr.3 \ tcsetpgrp.3 \ tcsetsid.3 \ + tcsetwinsize.3 \ time.3 \ times.3 \ timespec_get.3 \ @@ -528,6 +529,7 @@ tcsetattr.3 cfsetospeed.3 \ tcsetattr.3 cfsetspeed.3 \ tcsetattr.3 tcgetattr.3 +MLINKS+=tcsetwinsize.3 tcgetwinsize.3 MLINKS+=ttyname.3 isatty.3 \ ttyname.3 ttyname_r.3 MLINKS+=tzset.3 tzsetwall.3 Index: lib/libc/gen/tcsetwinsize.3 =================================================================== --- /dev/null +++ lib/libc/gen/tcsetwinsize.3 @@ -0,0 +1,178 @@ +.\"- +.\" Copyright (c) 2020 Soumendra Ganguly +.\" +.\" Copyright (c) 1995-2020 The FreeBSD Project +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL [your name] OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd December 27, 2020 +.Dt TCSETWINSIZE 3 +.Os +.Sh NAME +.Nm tcgetwinsize , +.Nm tcsetwinsize +.Nd get, set the size of a terminal window +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In termios.h +.Bd -literal +struct winsize { + unsigned short ws_row; /* number of rows, in characters */ + unsigned short ws_col; /* number of columns, in characters */ + unsigned short ws_xpixel; /* horizontal size, in pixels */ + unsigned short ws_ypixel; /* vertical size, in pixels */ +}; +.Ed +.Pp +.Ft int +.Fn tcgetwinsize "int fd" "struct winsize *w" +.Ft int +.Fn tcsetwinsize "int fd" "const struct winsize *w" +.Sh DESCRIPTION +The +.Fn tcgetwinsize +function gets the terminal window size of the terminal of which +.Fa fd +is an open file descriptor and stores it in the +.Fa winsize +structure of which +.Fa w +is a pointer. +.Pp +The +.Fn tcsetwinsize +function sets the terminal window size of the terminal of which +.Fa fd +is an open file descriptor from the +.Fa winsize +structure referenced by +.Fa w . +The change occurs immediately. If the terminal window size of the terminal +is changed successfully to have a value that is different from the value that +it had before the +.Fn tcsetwinsize +call, then +.Dv SIGWINCH +is sent to all those members of the foreground process group of the terminal +that have the terminal as their controlling terminal. See +.Xr sigaction 2 . +.Pp +The above declaration of +.Vt "struct winsize" +may not be literal. It is provided only to list the accessible members. +Therefore, before calling +.Fn tcsetwinsize , +the members of the +.Fa winsize +structure must be initialized by calling +.Fn tcgetwinsize +as follows: +.Bd -literal + struct winsize ws; + + if (tcgetwinsize(fd, &ws) == 0) { + /* make necessary modifications + * to documented members of ws here + */ + + tcsetwinsize(fd, &ws); + } +.Ed +.Pp +See +.In sys/_winsize.h +for the actual declaration of +.Vt "struct winsize" . +.Sh RETURN VALUE +Upon successful completion, 0 is returned by these functions. Otherwise, +-1 is returned and +.Va errno +is set to indicate the error. The terminal window size remains unchanged if +.Fn tcsetwinsize +fails. +.Pp +.Sh ERRORS +The following are the possible failure conditions: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa fd +argument to +.Fn tcgetwinsize +or to +.Fn tcsetwinsize +is not a valid file descriptor. +.It Bq Er ENOTTY +The +.Fa fd +argument to +.Fn tcgetwinsize +or to +.Fn tcsetwinsize +is not associated with a character special device. +.It Bq Er EINVAL +The +.Fa w +argument to +.Fn tcsetwinsize +is not valid. +.It Bq Er EFAULT +The +.Fa w +argument to +.Fn tcgetwinsize +or to +.Fn tcsetwinsize +points outside the process's allocated address space. +.El +.Sh IMPLEMENTATION NOTES +The +.Fn tcgetwinsize +function is a wrapper around the +.Dv TIOCGWINSZ +ioctl. The +.Fn tcsetwinsize +function is a wrapper around the +.Dv TIOCSWINSZ +ioctl. +.Sh SEE ALSO +.Xr stty 1 , +.Xr ioctl 2 , +.Xr sigaction 2 , +.Xr termios 4 , +.Xr tty 4 +.Sh STANDARDS +The +.Fn tcgetwinsize +and +.Fn tcsetwinsize +functions are expected to conform to issue 8 of +.St -p1003.1 . +The standard does not specify the +.Fa ws_xpixel +and +.Fa ws_ypixel +members of +.Vt "struct winsize" .