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