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: src/lib/libc/gen/tcsetattr.3,v 1.6.2.4 2002/12/29 16:35:34 schweikh Exp $ 30.\" 31.Dd August 10, 2016 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 tcgetattr , 42.Nm tcsetattr 43.Nd manipulating the termios structure 44.Sh LIBRARY 45.Lb libc 46.Sh SYNOPSIS 47.In termios.h 48.Ft speed_t 49.Fn cfgetispeed "const struct termios *t" 50.Ft int 51.Fn cfsetispeed "struct termios *t" "speed_t speed" 52.Ft speed_t 53.Fn cfgetospeed "const struct termios *t" 54.Ft int 55.Fn cfsetospeed "struct termios *t" "speed_t speed" 56.Ft int 57.Fn cfsetspeed "struct termios *t" "speed_t speed" 58.Ft void 59.Fn cfmakeraw "struct termios *t" 60.Ft int 61.Fn tcgetattr "int fd" "struct termios *t" 62.Ft int 63.Fn tcsetattr "int fd" "int action" "const struct termios *t" 64.Sh DESCRIPTION 65The 66.Fn cfmakeraw , 67.Fn tcgetattr 68and 69.Fn tcsetattr 70functions are provided for getting and setting the termios structure. 71.Pp 72The 73.Fn cfgetispeed , 74.Fn cfsetispeed , 75.Fn cfgetospeed , 76.Fn cfsetospeed 77and 78.Fn cfsetspeed 79functions are provided for getting and setting the baud rate values in 80the termios structure. 81The effects of the functions on the terminal as described below 82do not become effective, nor are all errors detected, until the 83.Fn tcsetattr 84function is called. 85Certain values for baud rates set in the termios structure and passed to 86.Fn tcsetattr 87have special meanings. 88These are discussed in the portion of the manual page that describes the 89.Fn tcsetattr 90function. 91.Sh GETTING AND SETTING THE BAUD RATE 92The input and output baud rates are found in the termios structure. 93The unsigned integer 94.Li speed_t 95is typedef'd in the include file 96.In termios.h . 97The value of the integer corresponds directly to the baud rate being 98represented, however, the following symbolic values are defined. 99.Bd -literal 100#define B0 0 101#define B50 50 102#define B75 75 103#define B110 110 104#define B134 134 105#define B150 150 106#define B200 200 107#define B300 300 108#define B600 600 109#define B1200 1200 110#define B1800 1800 111#define B2400 2400 112#define B4800 4800 113#define B9600 9600 114#define B19200 19200 115#define B38400 38400 116#if __BSD_VISIBLE 117#define B7200 7200 118#define B14400 14400 119#define B28800 28800 120#define B57600 57600 121#define B76800 76800 122#define B115200 115200 123#define B230400 230400 124#define EXTA 19200 125#define EXTB 38400 126#endif /* __BSD_VISIBLE */ 127.Ed 128.Pp 129The 130.Fn cfgetispeed 131function returns the input baud rate in the termios structure referenced by 132.Fa tp . 133.Pp 134The 135.Fn cfsetispeed 136function sets the input baud rate in the termios structure referenced by 137.Fa tp 138to 139.Fa speed . 140.Pp 141The 142.Fn cfgetospeed 143function returns the output baud rate in the termios structure referenced by 144.Fa tp . 145.Pp 146The 147.Fn cfsetospeed 148function sets the output baud rate in the termios structure referenced by 149.Fa tp 150to 151.Fa speed . 152.Pp 153The 154.Fn cfsetspeed 155function sets both the input and output baud rate in the termios structure 156referenced by 157.Fa tp 158to 159.Fa speed . 160.Pp 161Upon successful completion, the functions 162.Fn cfsetispeed , 163.Fn cfsetospeed , 164and 165.Fn cfsetspeed 166return a value of 0. 167Otherwise, a value of -1 is returned and the global variable 168.Va errno 169is set to indicate the error. 170.Sh GETTING AND SETTING THE TERMIOS STATE 171This section describes the functions that are used to control the general 172terminal interface. 173Unless otherwise noted for a specific command, these functions are restricted 174from use by background processes. 175Attempts to perform these operations shall cause the process group to be sent 176a 177.Dv SIGTTOU 178signal. 179If the calling process is blocking or ignoring 180.Dv SIGTTOU 181signals, the process is allowed to perform the operation and the 182.Dv SIGTTOU 183signal is not sent. 184.Pp 185In all the functions, although 186.Fa fd 187is an open file descriptor, the functions affect the underlying terminal 188file, not just the open file description associated with the particular 189file descriptor. 190.Pp 191The 192.Fn cfmakeraw 193function sets the flags stored in the termios structure to a state disabling 194all input and output processing, giving a 195.Dq raw I/O path . 196It should be noted that there is no function to reverse this effect. 197This is because there are a variety of processing options that could be 198re-enabled and the correct method is for an application to snapshot the 199current terminal state using the function 200.Fn tcgetattr , 201setting raw mode with 202.Fn cfmakeraw 203and the subsequent 204.Fn tcsetattr , 205and then using another 206.Fn tcsetattr 207with the saved state to revert to the previous terminal state. 208.Pp 209The 210.Fn tcgetattr 211function copies the parameters associated with the terminal referenced 212by 213.Fa fd 214in the termios structure referenced by 215.Fa tp . 216This function is allowed from a background process, however, the terminal 217attributes may be subsequently changed by a foreground process. 218.Pp 219The 220.Fn tcsetattr 221function sets the parameters associated with the terminal from the 222termios structure referenced by 223.Fa tp . 224The 225.Fa action 226field is created by 227.Em or Ns 'ing 228the following values, as specified in the include file 229.In termios.h . 230.Bl -tag -width ".Dv TCSADRAIN" 231.It Dv TCSANOW 232The change occurs immediately. 233.It Dv TCSADRAIN 234The change occurs after all output written to 235.Fa fd 236has been transmitted to the terminal. 237This value of 238.Fa action 239should be used when changing parameters that affect output. 240.It Dv TCSAFLUSH 241The change occurs after all output written to 242.Fa fd 243has been transmitted to the terminal. 244Additionally, any input that has been received but not read is discarded. 245.It Dv TCSASOFT 246If this value is 247.Em or Ns 'ed 248into the 249.Fa action 250value, the values of the 251.Em c_cflag , 252.Em c_ispeed , 253and 254.Em c_ospeed 255fields are ignored. 256.El 257.Pp 258The 0 baud rate is used to terminate the connection. 259If 0 is specified as the output speed to the function 260.Fn tcsetattr , 261modem control will no longer be asserted on the terminal, disconnecting 262the terminal. 263.Pp 264If zero is specified as the input speed to the function 265.Fn tcsetattr , 266the input baud rate will be set to the same value as that specified by 267the output baud rate. 268.Pp 269If 270.Fn tcsetattr 271is unable to make any of the requested changes, it returns -1 and 272sets 273.Va errno . 274Otherwise, it makes all of the requested changes it can. 275If the specified input and output baud rates differ and are a combination 276that is not supported, neither baud rate is changed. 277.Pp 278Upon successful completion, the functions 279.Fn tcgetattr 280and 281.Fn tcsetattr 282return a value of 0. 283Otherwise, they 284return -1 and the global variable 285.Va errno 286is set to indicate the error, as follows: 287.Bl -tag -width Er 288.It Bq Er EBADF 289The 290.Fa fd 291argument to 292.Fn tcgetattr 293or 294.Fn tcsetattr 295was not a valid file descriptor. 296.It Bq Er EINTR 297The 298.Fn tcsetattr 299function was interrupted by a signal. 300.It Bq Er EINVAL 301The 302.Fa action 303argument to the 304.Fn tcsetattr 305function was not valid, or an attempt was made to change an attribute 306represented in the termios structure to an unsupported value. 307.It Bq Er ENOTTY 308The file associated with the 309.Fa fd 310argument to 311.Fn tcgetattr 312or 313.Fn tcsetattr 314is not a terminal. 315.El 316.Sh SEE ALSO 317.Xr tcsendbreak 3 , 318.Xr termios 4 319.Sh STANDARDS 320The 321.Fn cfgetispeed , 322.Fn cfsetispeed , 323.Fn cfgetospeed , 324.Fn cfsetospeed , 325.Fn tcgetattr 326and 327.Fn tcsetattr 328functions are expected to be compliant with the 329.St -p1003.1-88 330specification. 331The 332.Fn cfmakeraw 333and 334.Fn cfsetspeed 335functions, 336as well as the 337.Dv TCSASOFT 338option to the 339.Fn tcsetattr 340function are extensions to the 341.St -p1003.1-88 342specification. 343