[BACK]Return to tcgetwinsize.3 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / termios

File: [cvs.NetBSD.org] / src / lib / libc / termios / tcgetwinsize.3 (download)

Revision 1.2, Mon Oct 30 15:43:21 2017 UTC (2 years, 11 months ago) by wiz
Branch: MAIN
CVS Tags: phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, netbsd-9-base, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, is-mlppp-base, is-mlppp, HEAD
Changes since 1.1: +4 -5 lines

Remove empty Fd. Use minus for return value. End list. Sort SEE ALSO.

.\" $NetBSD: tcgetwinsize.3,v 1.2 2017/10/30 15:43:21 wiz Exp $
.\"
.\" Copyright (c) 2017 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" 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 NETBSD FOUNDATION, INC. 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 THE FOUNDATION 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.
.\"
.Dd October 25, 2017
.Dt TCGETWINSIZE 3
.Os
.Sh NAME
.Nm tcgetwinsize ,
.Nm tcsetwinsize
.Nd manipulate terminal window size
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In termios.h
.Ft int
.Fn tcgetwinsize "int fd" "struct winsize *gws"
.Ft int
.Fn tcsetwinsize "int fd" "const struct winsize *sws"
.Sh DESCRIPTION
The
.Nm tcgetwinsize
function fills in the
.Ic winsize
structure pointed to by
.Fa gws
with values that represent the size of the
terminal window for which
.Fa fd
provides an open file descriptor.
If no error occurs
.Fn tcgetwinsize
returns zero (0).
.Pp
The
.Nm tcsetwinsize
function sets the terminal window size,
for the terminal referenced by
.Fa fd ,
to the sizes from the
.Ic winsize
structure pointed to by
.Fa sws .
If no error occurs
.Fn tcsetwinsize
returns zero (0).
.Pp
The
.Ic winsize
structure, defined in
.In termios.h ,
contains (at least) the following four fields
.Bd -literal
	unsigned short ws_row;      /* Number of rows, in characters */
	unsigned short ws_col;      /* Number of columns, in characters */
	unsigned short ws_xpixel;   /* Width, in pixels */
	unsigned short ws_ypixel;   /* Height, in pixels */
.Ed
.Pp
If the actual window size of the controlling terminal
of a process changes, the process is sent a
.Dv SIGWINCH
signal.
See
.Xr signal 7 .
Note simply changing the sizes using
.Fn tcsetwinsize
does not necessarily change the actual window size,
and if not, will not generate a
.Dv SIGWINCH .
.Sh ERRORS
If an error occurs,
.Fn tcgetwinsize
and
.Fn tcsetwinsize
return \-1 and cause the global variable
.Va errno
to be set to indicate the error.
Common errors are as follows:
.Bl -tag -width Er
.It Bq Er EBADF
The
.Fa fd
argument to
.Fn tcgetwinsize
or
.Fn tcsetwinsize
is not a valid file descriptor.
.It Bq Er EFAULT
The
.Fa gws
argument to
.Fn tcgetwinsize
does not point to a suitable location
into which to store the resulting
.Ic winsize
structure,
or the
.Fa sws
argument to
.Fn tcsetwinsize
does not refer to a suitable location
from which the
.Ic winsize
structure can be obtained.
.It Bq Er EINVAL
The values passed in the
.Ar sws
.Ic winsize
structure to
.Fn tcsetwinsize
represent an attempt to set the window size to an invalid state.
.It Bq Er ENOTTY
The
.Fa fd
argument to
.Fn tcgetwinsize
or
.Fn tcsetwinsize
does not represent a terminal device capable
of remembering a window size.
.El
.Sh SEE ALSO
.Xr stty 1 ,
.Xr pty 4 ,
.Xr termios 4 ,
.Xr tty 4 ,
.Xr signal 7
.Sh STANDARDS
The
.Nm tcgetwinsize
and
.Nm tcsetwinsize
functions will conform to
.St -p1003.1
issue 8, when it is published.
.Pp
The
.Ic ws_xpixel
and
.Ic ws_ypixel
fields are extensions to the standard.
.Pp
The standard only requires pseudo-terminals
.Pq Xr pty 4
to support these operations.
In
.Nx
all terminal devices can set and recall a window size,
regardless of whether any actual window exists.
.Sh HISTORY
The
.Fn tcgetwinsize
and
.Fn tcsetwinsize
functions were added in
.Nx 8.0
after specification by POSIX
as more portable alternatives to ancient
.Ic ioctl
operations from
.Bx 4.3 .
.Sh CAVEATS
It is unspecified whether calling the
.Nm tcsetwinsize
function causes the underlying terminal window to be resized.
Nor is it specified whether altering the relationship between
the character fields (ws_row and ws_col) and the pixel fields
(ws_xpixel and ws_ypixel) causes the font size to change, or
whether the application is required to maintain any specific
relationship between these fields.
In general, the
.Nm tcsetwinsize
function is best avoided except by applications responsible
for actually implementing terminal windows.
.Pp
As the
.Ic winsize
structure may have more fields than documented, applications
planning to call
.Fn tcsetwinsize
should call
.Fn tcgetwinsize
first with the same
.Ar fd
parameter, and use the result obtained in
.Ar *gws
to initialize the
.Ic winsize
structure to be used (after altering fields that are to be changed)
as the
.Ar sws
operand of
.Nm tcsetwinsize .