1.\" Copyright (c) 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.\" @(#)tcsetattr.3 8.3 (Berkeley) 1/2/94 29.\" $FreeBSD$ 30.\" 31.Dd July 15, 2020 32.Dt TCSETATTR 3 33.Os 34.Sh NAME 35.Nm cfgetispeed , 36.Nm cfsetispeed , 37.Nm cfgetospeed , 38.Nm cfsetospeed , 39.Nm cfsetspeed , 40.Nm cfmakeraw , 41.Nm cfmakesane , 42.Nm tcgetattr , 43.Nm tcsetattr 44.Nd manipulating the termios structure 45.Sh LIBRARY 46.Lb libc 47.Sh SYNOPSIS 48.In termios.h 49.Ft speed_t 50.Fn cfgetispeed "const struct termios *t" 51.Ft int 52.Fn cfsetispeed "struct termios *t" "speed_t speed" 53.Ft speed_t 54.Fn cfgetospeed "const struct termios *t" 55.Ft int 56.Fn cfsetospeed "struct termios *t" "speed_t speed" 57.Ft int 58.Fn cfsetspeed "struct termios *t" "speed_t speed" 59.Ft void 60.Fn cfmakeraw "struct termios *t" 61.Ft void 62.Fn cfmakesane "struct termios *t" 63.Ft int 64.Fn tcgetattr "int fd" "struct termios *t" 65.Ft int 66.Fn tcsetattr "int fd" "int action" "const struct termios *t" 67.Sh DESCRIPTION 68The 69.Fn cfmakeraw , 70.Fn cfmakesane , 71.Fn tcgetattr 72and 73.Fn tcsetattr 74functions are provided for getting and setting the termios structure. 75.Pp 76The 77.Fn cfgetispeed , 78.Fn cfsetispeed , 79.Fn cfgetospeed , 80.Fn cfsetospeed 81and 82.Fn cfsetspeed 83functions are provided for getting and setting the baud rate values in 84the termios structure. 85The effects of the functions on the terminal as described below 86do not become effective, nor are all errors detected, until the 87.Fn tcsetattr 88function is called. 89Certain values for baud rates set in the termios structure and passed to 90.Fn tcsetattr 91have special meanings. 92These are discussed in the portion of the manual page that describes the 93.Fn tcsetattr 94function. 95.Sh GETTING AND SETTING THE BAUD RATE 96The input and output baud rates are found in the termios structure. 97The unsigned integer 98.Li speed_t 99is typedef'd in the include file 100.In termios.h . 101The value of the integer corresponds directly to the baud rate being 102represented, however, the following symbolic values are defined. 103.Bd -literal 104#define B0 0 105#define B50 50 106#define B75 75 107#define B110 110 108#define B134 134 109#define B150 150 110#define B200 200 111#define B300 300 112#define B600 600 113#define B1200 1200 114#define B1800 1800 115#define B2400 2400 116#define B4800 4800 117#define B9600 9600 118#define B19200 19200 119#define B38400 38400 120#ifndef _POSIX_SOURCE 121#define EXTA 19200 122#define EXTB 38400 123#endif /*_POSIX_SOURCE */ 124.Ed 125.Pp 126The 127.Fn cfgetispeed 128function returns the input baud rate in the termios structure referenced by 129.Fa t . 130.Pp 131The 132.Fn cfsetispeed 133function sets the input baud rate in the termios structure referenced by 134.Fa t 135to 136.Fa speed . 137.Pp 138The 139.Fn cfgetospeed 140function returns the output baud rate in the termios structure referenced by 141.Fa t . 142.Pp 143The 144.Fn cfsetospeed 145function sets the output baud rate in the termios structure referenced by 146.Fa t 147to 148.Fa speed . 149.Pp 150The 151.Fn cfsetspeed 152function sets both the input and output baud rate in the termios structure 153referenced by 154.Fa t 155to 156.Fa speed . 157.Pp 158Upon successful completion, the functions 159.Fn cfsetispeed , 160.Fn cfsetospeed , 161and 162.Fn cfsetspeed 163return a value of 0. 164Otherwise, a value of -1 is returned and the global variable 165.Va errno 166is set to indicate the error. 167.Sh GETTING AND SETTING THE TERMIOS STATE 168This section describes the functions that are used to control the general 169terminal interface. 170Unless otherwise noted for a specific command, these functions are restricted 171from use by background processes. 172Attempts to perform these operations shall cause the process group to be sent 173a SIGTTOU signal. 174If the calling process is blocking or ignoring SIGTTOU signals, the process 175is allowed to perform the operation and the SIGTTOU signal is not sent. 176.Pp 177In all the functions, although 178.Fa fd 179is an open file descriptor, the functions affect the underlying terminal 180file, not just the open file description associated with the particular 181file descriptor. 182.Pp 183The 184.Fn cfmakeraw 185function sets the flags stored in the termios structure to a state disabling 186all input and output processing, giving a 187.Dq raw I/O path , 188while the 189.Fn cfmakesane 190function sets them to a state similar to those of a newly created 191terminal device. 192It should be noted that there is no function to reverse this effect. 193This is because there are a variety of processing options that could be 194re-enabled and the correct method is for an application to snapshot the 195current terminal state using the function 196.Fn tcgetattr , 197setting raw or sane mode with 198.Fn cfmakeraw 199or 200.Fn cfmakesane 201and the subsequent 202.Fn tcsetattr , 203and then using another 204.Fn tcsetattr 205with the saved state to revert to the previous terminal state. 206.Pp 207The 208.Fn tcgetattr 209function copies the parameters associated with the terminal referenced 210by 211.Fa fd 212in the termios structure referenced by 213.Fa t . 214This function is allowed from a background process, however, the terminal 215attributes may be subsequently changed by a foreground process. 216.Pp 217The 218.Fn tcsetattr 219function sets the parameters associated with the terminal from the 220termios structure referenced by 221.Fa t . 222The 223.Fa action 224argument is one of 225the following values, as specified in the include file 226.In termios.h . 227.Bl -tag -width "TCSADRAIN" 228.It Fa TCSANOW 229The change occurs immediately. 230.It Fa TCSADRAIN 231The change occurs after all output written to 232.Fa fd 233has been transmitted to the terminal. 234This value of 235.Fa action 236should be used when changing parameters that affect output. 237.It Fa TCSAFLUSH 238The change occurs after all output written to 239.Fa fd 240has been transmitted to the terminal. 241Additionally, any input that has been received but not read is discarded. 242.El 243.Pp 244The 245.Fa action 246may be modified by 247.Em or Ns 'ing 248in 249.Fa TCSASOFT 250which causes the values of the 251.Va c_cflag , 252.Va c_ispeed , 253and 254.Va c_ospeed 255fields to be ignored. 256.Pp 257The 0 baud rate is used to terminate the connection. 258If 0 is specified as the output speed to the function 259.Fn tcsetattr , 260modem control will no longer be asserted on the terminal, disconnecting 261the terminal. 262.Pp 263If zero is specified as the input speed to the function 264.Fn tcsetattr , 265the input baud rate will be set to the same value as that specified by 266the output baud rate. 267.Pp 268If 269.Fn tcsetattr 270is unable to make any of the requested changes, it returns -1 and 271sets errno. 272Otherwise, it makes all of the requested changes it can. 273If the specified input and output baud rates differ and are a combination 274that is not supported, neither baud rate is changed. 275.Pp 276Upon successful completion, the functions 277.Fn tcgetattr 278and 279.Fn tcsetattr 280return a value of 0. 281Otherwise, they 282return -1 and the global variable 283.Va errno 284is set to indicate the error, as follows: 285.Bl -tag -width Er 286.It Bq Er EBADF 287The 288.Fa fd 289argument to 290.Fn tcgetattr 291or 292.Fn tcsetattr 293was not a valid file descriptor. 294.It Bq Er EINTR 295The 296.Fn tcsetattr 297function was interrupted by a signal. 298.It Bq Er EINVAL 299The 300.Fa action 301argument to the 302.Fn tcsetattr 303function was not valid, or an attempt was made to change an attribute 304represented in the termios structure to an unsupported value. 305.It Bq Er ENOTTY 306The file associated with the 307.Fa fd 308argument to 309.Fn tcgetattr 310or 311.Fn tcsetattr 312is not a terminal. 313.El 314.Sh SEE ALSO 315.Xr tcsendbreak 3 , 316.Xr termios 4 317.Sh STANDARDS 318The 319.Fn cfgetispeed , 320.Fn cfsetispeed , 321.Fn cfgetospeed , 322.Fn cfsetospeed , 323.Fn tcgetattr 324and 325.Fn tcsetattr 326functions are expected to be compliant with the 327.St -p1003.1-88 328specification. 329The 330.Fn cfmakeraw , 331.Fn cfmakesane 332and 333.Fn cfsetspeed 334functions, 335as well as the 336.Li TCSASOFT 337option to the 338.Fn tcsetattr 339function are extensions to the 340.St -p1003.1-88 341specification. 342