1*73be947eSjsg.\" $OpenBSD: tcsetattr.3,v 1.19 2023/01/12 12:56:07 jsg Exp $ 2df930be7Sderaadt.\" 3df930be7Sderaadt.\" Copyright (c) 1991 The Regents of the University of California. 4df930be7Sderaadt.\" All rights reserved. 5df930be7Sderaadt.\" 6df930be7Sderaadt.\" Redistribution and use in source and binary forms, with or without 7df930be7Sderaadt.\" modification, are permitted provided that the following conditions 8df930be7Sderaadt.\" are met: 9df930be7Sderaadt.\" 1. Redistributions of source code must retain the above copyright 10df930be7Sderaadt.\" notice, this list of conditions and the following disclaimer. 11df930be7Sderaadt.\" 2. Redistributions in binary form must reproduce the above copyright 12df930be7Sderaadt.\" notice, this list of conditions and the following disclaimer in the 13df930be7Sderaadt.\" documentation and/or other materials provided with the distribution. 146580fee3Smillert.\" 3. Neither the name of the University nor the names of its contributors 15df930be7Sderaadt.\" may be used to endorse or promote products derived from this software 16df930be7Sderaadt.\" without specific prior written permission. 17df930be7Sderaadt.\" 18df930be7Sderaadt.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19df930be7Sderaadt.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20df930be7Sderaadt.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21df930be7Sderaadt.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22df930be7Sderaadt.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23df930be7Sderaadt.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24df930be7Sderaadt.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25df930be7Sderaadt.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26df930be7Sderaadt.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27df930be7Sderaadt.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28df930be7Sderaadt.\" SUCH DAMAGE. 29df930be7Sderaadt.\" 30*73be947eSjsg.Dd $Mdocdate: January 12 2023 $ 31df930be7Sderaadt.Dt TCSETATTR 3 32df930be7Sderaadt.Os 33df930be7Sderaadt.Sh NAME 34df930be7Sderaadt.Nm cfgetispeed , 35df930be7Sderaadt.Nm cfsetispeed , 36df930be7Sderaadt.Nm cfgetospeed , 37df930be7Sderaadt.Nm cfsetospeed , 38df930be7Sderaadt.Nm cfsetspeed , 39df930be7Sderaadt.Nm cfmakeraw , 40df930be7Sderaadt.Nm tcgetattr , 41df930be7Sderaadt.Nm tcsetattr 42df930be7Sderaadt.Nd manipulating the termios structure 43df930be7Sderaadt.Sh SYNOPSIS 4464d4e987Stedu.In termios.h 45df930be7Sderaadt.Ft speed_t 46617372beShugh.Fn cfgetispeed "const struct termios *tp" 47df930be7Sderaadt.Ft int 48617372beShugh.Fn cfsetispeed "struct termios *tp" "speed_t speed" 49df930be7Sderaadt.Ft speed_t 50617372beShugh.Fn cfgetospeed "const struct termios *tp" 51df930be7Sderaadt.Ft int 52617372beShugh.Fn cfsetospeed "struct termios *tp" "speed_t speed" 5378b25fe5Sderaadt.Ft int 54617372beShugh.Fn cfsetspeed "struct termios *tp" "speed_t speed" 55df930be7Sderaadt.Ft void 56617372beShugh.Fn cfmakeraw "struct termios *tp" 57df930be7Sderaadt.Ft int 58617372beShugh.Fn tcgetattr "int fd" "struct termios *tp" 59df930be7Sderaadt.Ft int 60617372beShugh.Fn tcsetattr "int fd" "int action" "const struct termios *tp" 61df930be7Sderaadt.Sh DESCRIPTION 62df930be7SderaadtThe 63054695e9Saaron.Fn cfmakeraw , 64054695e9Saaron.Fn tcgetattr , 65df930be7Sderaadtand 66054695e9Saaron.Fn tcsetattr 67054695e9Saaronfunctions are provided for getting and setting the 68d32639f6Sjmc.Vt termios 69054695e9Saaronstructure. 70df930be7Sderaadt.Pp 71df930be7SderaadtThe 72054695e9Saaron.Fn cfgetispeed , 73054695e9Saaron.Fn cfsetispeed , 74054695e9Saaron.Fn cfgetospeed , 75054695e9Saaron.Fn cfsetospeed , 76df930be7Sderaadtand 77054695e9Saaron.Fn cfsetspeed 78df930be7Sderaadtfunctions are provided for getting and setting the baud rate values in 79054695e9Saaronthe 80d32639f6Sjmc.Vt termios 81054695e9Saaronstructure. 82df930be7SderaadtThe effects of the functions on the terminal as described below 83df930be7Sderaadtdo not become effective, nor are all errors detected, until the 84054695e9Saaron.Fn tcsetattr 85df930be7Sderaadtfunction is called. 86054695e9SaaronCertain values for baud rates set in the 87d32639f6Sjmc.Vt termios 88054695e9Saaronstructure and passed to 89054695e9Saaron.Fn tcsetattr 90df930be7Sderaadthave special meanings. 91df930be7SderaadtThese are discussed in the portion of the manual page that describes the 92054695e9Saaron.Fn tcsetattr 93df930be7Sderaadtfunction. 94df930be7Sderaadt.Sh GETTING AND SETTING THE BAUD RATE 95054695e9SaaronThe input and output baud rates are found in the 96d32639f6Sjmc.Vt termios 97054695e9Saaronstructure. 98df930be7SderaadtThe unsigned integer 99d32639f6Sjmc.Vt speed_t 100ccc594cdSpjanzenis typedef'd in the include file 101369bef3aSschwarze.In termios.h . 10271019e05SmillertOn 10371019e05Smillert.Ox , 10471019e05Smillertthe value of the integer corresponds directly to the baud rate being 10571019e05Smillertrepresented. 10671019e05SmillertHowever, this is not true of all systems and new code should use the 10771019e05Smillertsymbolic value for maximum portability. 10871019e05Smillert.Bd -literal -offset indent 109df930be7Sderaadt#define B0 0 110df930be7Sderaadt#define B50 50 111df930be7Sderaadt#define B75 75 112df930be7Sderaadt#define B110 110 113df930be7Sderaadt#define B134 134 114df930be7Sderaadt#define B150 150 115df930be7Sderaadt#define B200 200 116df930be7Sderaadt#define B300 300 117df930be7Sderaadt#define B600 600 118df930be7Sderaadt#define B1200 1200 119df930be7Sderaadt#define B1800 1800 120df930be7Sderaadt#define B2400 2400 121df930be7Sderaadt#define B4800 4800 122df930be7Sderaadt#define B9600 9600 123df930be7Sderaadt#define B19200 19200 124df930be7Sderaadt#define B38400 38400 125df930be7Sderaadt#ifndef _POSIX_SOURCE 126df930be7Sderaadt#define EXTA 19200 127df930be7Sderaadt#define EXTB 38400 128df930be7Sderaadt#endif /*_POSIX_SOURCE */ 129df930be7Sderaadt.Ed 130df930be7Sderaadt.Pp 131df930be7SderaadtThe 132054695e9Saaron.Fn cfgetispeed 133054695e9Saaronfunction returns the input baud rate in the 134d32639f6Sjmc.Vt termios 135054695e9Saaronstructure referenced by 136df930be7Sderaadt.Fa tp . 137df930be7Sderaadt.Pp 138df930be7SderaadtThe 139054695e9Saaron.Fn cfsetispeed 140054695e9Saaronfunction sets the input baud rate in the 141d32639f6Sjmc.Vt termios 142054695e9Saaronstructure referenced by 143df930be7Sderaadt.Fa tp 144df930be7Sderaadtto 145df930be7Sderaadt.Fa speed . 146df930be7Sderaadt.Pp 147df930be7SderaadtThe 148054695e9Saaron.Fn cfgetospeed 149054695e9Saaronfunction returns the output baud rate in the 150d32639f6Sjmc.Vt termios 151054695e9Saaronstructure referenced by 152df930be7Sderaadt.Fa tp . 153df930be7Sderaadt.Pp 154df930be7SderaadtThe 155054695e9Saaron.Fn cfsetospeed 156054695e9Saaronfunction sets the output baud rate in the 157d32639f6Sjmc.Vt termios 158054695e9Saaronstructure referenced by 159df930be7Sderaadt.Fa tp 160df930be7Sderaadtto 161df930be7Sderaadt.Fa speed . 162df930be7Sderaadt.Pp 163df930be7SderaadtThe 164054695e9Saaron.Fn cfsetspeed 165054695e9Saaronfunction sets both the input and output baud rate in the 166d32639f6Sjmc.Vt termios 167054695e9Saaronstructure referenced by 168df930be7Sderaadt.Fa tp 169df930be7Sderaadtto 170df930be7Sderaadt.Fa speed . 171df930be7Sderaadt.Pp 172df930be7SderaadtUpon successful completion, the functions 173054695e9Saaron.Fn cfsetispeed , 174054695e9Saaron.Fn cfsetospeed , 175df930be7Sderaadtand 176054695e9Saaron.Fn cfsetspeed 177df930be7Sderaadtreturn a value of 0. 178054695e9SaaronOtherwise, a value of \-1 is returned and the global variable 179df930be7Sderaadt.Va errno 180df930be7Sderaadtis set to indicate the error. 181df930be7Sderaadt.Sh GETTING AND SETTING THE TERMIOS STATE 182df930be7SderaadtThis section describes the functions that are used to control the general 183df930be7Sderaadtterminal interface. 184df930be7SderaadtUnless otherwise noted for a specific command, these functions are restricted 185df930be7Sderaadtfrom use by background processes. 186df930be7SderaadtAttempts to perform these operations shall cause the process group to be sent 18702cdb9c2Saarona 18802cdb9c2Saaron.Dv SIGTTOU 18902cdb9c2Saaronsignal. 19002cdb9c2SaaronIf the calling process is blocking or ignoring 19102cdb9c2Saaron.Dv SIGTTOU 19202cdb9c2Saaronsignals, the process 19302cdb9c2Saaronis allowed to perform the operation and the 19402cdb9c2Saaron.Dv SIGTTOU 19502cdb9c2Saaronsignal is not sent. 196df930be7Sderaadt.Pp 197df930be7SderaadtIn all the functions, although 198df930be7Sderaadt.Fa fd 199df930be7Sderaadtis an open file descriptor, the functions affect the underlying terminal 200df930be7Sderaadtfile, not just the open file description associated with the particular 201df930be7Sderaadtfile descriptor. 202df930be7Sderaadt.Pp 203df930be7SderaadtThe 204054695e9Saaron.Fn cfmakeraw 205054695e9Saaronfunction sets the flags stored in the 206d32639f6Sjmc.Vt termios 207054695e9Saaronstructure to a state disabling 208df930be7Sderaadtall input and output processing, giving a 209df930be7Sderaadt.Dq raw I/O path . 210df930be7SderaadtIt should be noted that there is no function to reverse this effect. 211df930be7SderaadtThis is because there are a variety of processing options that could be 212df930be7Sderaadtre-enabled and the correct method is for an application to snapshot the 213df930be7Sderaadtcurrent terminal state using the function 214054695e9Saaron.Fn tcgetattr , 215df930be7Sderaadtsetting raw mode with 216054695e9Saaron.Fn cfmakeraw 217df930be7Sderaadtand the subsequent 218054695e9Saaron.Fn tcsetattr , 219df930be7Sderaadtand then using another 220054695e9Saaron.Fn tcsetattr 221df930be7Sderaadtwith the saved state to revert to the previous terminal state. 222df930be7Sderaadt.Pp 223df930be7SderaadtThe 224054695e9Saaron.Fn tcgetattr 225df930be7Sderaadtfunction copies the parameters associated with the terminal referenced 226df930be7Sderaadtby 227df930be7Sderaadt.Fa fd 228054695e9Saaronin the 229d32639f6Sjmc.Vt termios 230054695e9Saaronstructure referenced by 231df930be7Sderaadt.Fa tp . 232ccc594cdSpjanzenThis function is allowed from a background process, although the terminal 233df930be7Sderaadtattributes may be subsequently changed by a foreground process. 234df930be7Sderaadt.Pp 235df930be7SderaadtThe 236054695e9Saaron.Fn tcsetattr 237df930be7Sderaadtfunction sets the parameters associated with the terminal from the 238d32639f6Sjmc.Vt termios 239054695e9Saaronstructure referenced by 240df930be7Sderaadt.Fa tp . 241df930be7SderaadtThe 242df930be7Sderaadt.Fa action 243df930be7Sderaadtfield is created by 24402cdb9c2Saaron.Tn OR Ns 'ing 245df930be7Sderaadtthe following values, as specified in the include file 246369bef3aSschwarze.In termios.h . 247df930be7Sderaadt.Bl -tag -width "TCSADRAIN" 24802cdb9c2Saaron.It Dv TCSANOW 249df930be7SderaadtThe change occurs immediately. 25002cdb9c2Saaron.It Dv TCSADRAIN 251df930be7SderaadtThe change occurs after all output written to 252df930be7Sderaadt.Fa fd 253df930be7Sderaadthas been transmitted to the terminal. 254df930be7SderaadtThis value of 255df930be7Sderaadt.Fa action 256df930be7Sderaadtshould be used when changing parameters that affect output. 25702cdb9c2Saaron.It Dv TCSAFLUSH 258df930be7SderaadtThe change occurs after all output written to 259df930be7Sderaadt.Fa fd 2609a3cdba5Sjmchas been transmitted to the terminal. 261df930be7SderaadtAdditionally, any input that has been received but not read is discarded. 26202cdb9c2Saaron.It Dv TCSASOFT 263df930be7SderaadtIf this value is 26402cdb9c2Saaron.Tn OR Ns 'ed 265df930be7Sderaadtinto the 266df930be7Sderaadt.Fa action 267df930be7Sderaadtvalue, the values of the 268054695e9Saaron.Fa c_cflag , 269054695e9Saaron.Fa c_ispeed , 270df930be7Sderaadtand 271054695e9Saaron.Fa c_ospeed 272df930be7Sderaadtfields are ignored. 273df930be7Sderaadt.El 274df930be7Sderaadt.Pp 275df930be7SderaadtThe 0 baud rate is used to terminate the connection. 276df930be7SderaadtIf 0 is specified as the output speed to the function 277054695e9Saaron.Fn tcsetattr , 278df930be7Sderaadtmodem control will no longer be asserted on the terminal, disconnecting 279df930be7Sderaadtthe terminal. 280df930be7Sderaadt.Pp 281df930be7SderaadtIf zero is specified as the input speed to the function 282054695e9Saaron.Fn tcsetattr , 283df930be7Sderaadtthe input baud rate will be set to the same value as that specified by 284df930be7Sderaadtthe output baud rate. 2859a3cdba5Sjmc.Sh RETURN VALUES 286df930be7SderaadtIf 287054695e9Saaron.Fn tcsetattr 2889a3cdba5Sjmcis unable to make any of the requested changes, it returns \-1 and 289df930be7Sderaadtsets 290df930be7Sderaadt.Va errno . 291df930be7SderaadtOtherwise, it makes all of the requested changes it can. 292df930be7SderaadtIf the specified input and output baud rates differ and are a combination 293df930be7Sderaadtthat is not supported, neither baud rate is changed. 2949a3cdba5Sjmc.Sh ERRORS 295df930be7SderaadtUpon successful completion, the functions 296054695e9Saaron.Fn tcgetattr 297df930be7Sderaadtand 298054695e9Saaron.Fn tcsetattr 299df930be7Sderaadtreturn a value of 0. 300df930be7SderaadtOtherwise, they 301054695e9Saaronreturn \-1 and the global variable 302df930be7Sderaadt.Va errno 303df930be7Sderaadtis set to indicate the error, as follows: 304df930be7Sderaadt.Bl -tag -width Er 305df930be7Sderaadt.It Bq Er EBADF 306df930be7SderaadtThe 307df930be7Sderaadt.Fa fd 308df930be7Sderaadtargument to 309054695e9Saaron.Fn tcgetattr 310df930be7Sderaadtor 311054695e9Saaron.Fn tcsetattr 312df930be7Sderaadtwas not a valid file descriptor. 313df930be7Sderaadt.It Bq Er EINTR 314df930be7SderaadtThe 315054695e9Saaron.Fn tcsetattr 316df930be7Sderaadtfunction was interrupted by a signal. 317df930be7Sderaadt.It Bq Er EINVAL 318df930be7SderaadtThe 319df930be7Sderaadt.Fa action 320df930be7Sderaadtargument to the 321054695e9Saaron.Fn tcsetattr 322df930be7Sderaadtfunction was not valid, or an attempt was made to change an attribute 323054695e9Saaronrepresented in the 324d32639f6Sjmc.Vt termios 325054695e9Saaronstructure to an unsupported value. 326df930be7Sderaadt.It Bq Er ENOTTY 327df930be7SderaadtThe file associated with the 328df930be7Sderaadt.Fa fd 329df930be7Sderaadtargument to 330054695e9Saaron.Fn tcgetattr 331df930be7Sderaadtor 332054695e9Saaron.Fn tcsetattr 333df930be7Sderaadtis not a terminal. 334df930be7Sderaadt.El 335df930be7Sderaadt.Sh SEE ALSO 336df930be7Sderaadt.Xr tcsendbreak 3 , 337df930be7Sderaadt.Xr termios 4 338df930be7Sderaadt.Sh STANDARDS 339df930be7SderaadtThe 340054695e9Saaron.Fn cfgetispeed , 341054695e9Saaron.Fn cfsetispeed , 342054695e9Saaron.Fn cfgetospeed , 343054695e9Saaron.Fn cfsetospeed , 344054695e9Saaron.Fn tcgetattr , 345df930be7Sderaadtand 346054695e9Saaron.Fn tcsetattr 347*73be947eSjsgfunctions are compliant with the 348df930be7Sderaadt.St -p1003.1-88 349df930be7Sderaadtspecification. 350df930be7SderaadtThe 351054695e9Saaron.Fn cfmakeraw 352df930be7Sderaadtand 353054695e9Saaron.Fn cfsetspeed 354df930be7Sderaadtfunctions, 355df930be7Sderaadtas well as the 35602cdb9c2Saaron.Dv TCSASOFT 357df930be7Sderaadtoption to the 358054695e9Saaron.Fn tcsetattr 359df930be7Sderaadtfunction are extensions to the 360df930be7Sderaadt.St -p1003.1-88 361df930be7Sderaadtspecification. 362