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