xref: /dragonfly/lib/libc/gen/tcsetattr.3 (revision 6693db17)
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. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"	@(#)tcsetattr.3	8.3 (Berkeley) 1/2/94
33.\" $FreeBSD: src/lib/libc/gen/tcsetattr.3,v 1.6.2.4 2002/12/29 16:35:34 schweikh Exp $
34.\" $DragonFly: src/lib/libc/gen/tcsetattr.3,v 1.5 2007/09/08 20:50:49 swildner Exp $
35.\"
36.Dd January 2, 1994
37.Dt TCSETATTR 3
38.Os
39.Sh NAME
40.Nm cfgetispeed ,
41.Nm cfsetispeed ,
42.Nm cfgetospeed ,
43.Nm cfsetospeed ,
44.Nm cfsetspeed ,
45.Nm cfmakeraw ,
46.Nm tcgetattr ,
47.Nm tcsetattr
48.Nd manipulating the termios structure
49.Sh LIBRARY
50.Lb libc
51.Sh SYNOPSIS
52.In termios.h
53.Ft speed_t
54.Fn cfgetispeed "const struct termios *t"
55.Ft int
56.Fn cfsetispeed "struct termios *t" "speed_t speed"
57.Ft speed_t
58.Fn cfgetospeed "const struct termios *t"
59.Ft int
60.Fn cfsetospeed "struct termios *t" "speed_t speed"
61.Ft int
62.Fn cfsetspeed "struct termios *t" "speed_t speed"
63.Ft void
64.Fn cfmakeraw "struct termios *t"
65.Ft int
66.Fn tcgetattr "int fd" "struct termios *t"
67.Ft int
68.Fn tcsetattr "int fd" "int action" "const struct termios *t"
69.Sh DESCRIPTION
70The
71.Fn cfmakeraw ,
72.Fn tcgetattr
73and
74.Fn tcsetattr
75functions are provided for getting and setting the termios structure.
76.Pp
77The
78.Fn cfgetispeed ,
79.Fn cfsetispeed ,
80.Fn cfgetospeed ,
81.Fn cfsetospeed
82and
83.Fn cfsetspeed
84functions are provided for getting and setting the baud rate values in
85the termios structure.
86The effects of the functions on the terminal as described below
87do not become effective, nor are all errors detected, until the
88.Fn tcsetattr
89function is called.
90Certain values for baud rates set in the termios structure and passed to
91.Fn tcsetattr
92have special meanings.
93These are discussed in the portion of the manual page that describes the
94.Fn tcsetattr
95function.
96.Sh GETTING AND SETTING THE BAUD RATE
97The input and output baud rates are found in the termios structure.
98The unsigned integer
99.Li speed_t
100is typedef'd in the include file
101.In termios.h .
102The value of the integer corresponds directly to the baud rate being
103represented, however, the following symbolic values are defined.
104.Bd -literal
105#define B0	0
106#define B50	50
107#define B75	75
108#define B110	110
109#define B134	134
110#define B150	150
111#define B200	200
112#define B300	300
113#define B600	600
114#define B1200	1200
115#define	B1800	1800
116#define B2400	2400
117#define B4800	4800
118#define B9600	9600
119#define B19200	19200
120#define B38400	38400
121#ifndef _POSIX_SOURCE
122#define EXTA	19200
123#define EXTB	38400
124#endif  /*_POSIX_SOURCE */
125.Ed
126.Pp
127The
128.Fn cfgetispeed
129function returns the input baud rate in the termios structure referenced by
130.Fa tp .
131.Pp
132The
133.Fn cfsetispeed
134function sets the input baud rate in the termios structure referenced by
135.Fa tp
136to
137.Fa speed .
138.Pp
139The
140.Fn cfgetospeed
141function returns the output baud rate in the termios structure referenced by
142.Fa tp .
143.Pp
144The
145.Fn cfsetospeed
146function sets the output baud rate in the termios structure referenced by
147.Fa tp
148to
149.Fa speed .
150.Pp
151The
152.Fn cfsetspeed
153function sets both the input and output baud rate in the termios structure
154referenced by
155.Fa tp
156to
157.Fa speed .
158.Pp
159Upon successful completion, the functions
160.Fn cfsetispeed ,
161.Fn cfsetospeed ,
162and
163.Fn cfsetspeed
164return a value of 0.
165Otherwise, a value of -1 is returned and the global variable
166.Va errno
167is set to indicate the error.
168.Sh GETTING AND SETTING THE TERMIOS STATE
169This section describes the functions that are used to control the general
170terminal interface.
171Unless otherwise noted for a specific command, these functions are restricted
172from use by background processes.
173Attempts to perform these operations shall cause the process group to be sent
174a
175.Dv SIGTTOU
176signal.
177If the calling process is blocking or ignoring
178.Dv SIGTTOU
179signals, the process is allowed to perform the operation and the
180.Dv SIGTTOU
181signal is not sent.
182.Pp
183In all the functions, although
184.Fa fd
185is an open file descriptor, the functions affect the underlying terminal
186file, not just the open file description associated with the particular
187file descriptor.
188.Pp
189The
190.Fn cfmakeraw
191function sets the flags stored in the termios structure to a state disabling
192all input and output processing, giving a
193.Dq raw I/O path .
194It should be noted that there is no function to reverse this effect.
195This is because there are a variety of processing options that could be
196re-enabled and the correct method is for an application to snapshot the
197current terminal state using the function
198.Fn tcgetattr ,
199setting raw mode with
200.Fn cfmakeraw
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 tp .
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 tp .
222The
223.Fa action
224field is created by
225.Em or Ns 'ing
226the following values, as specified in the include file
227.In termios.h .
228.Bl -tag -width ".Dv TCSADRAIN"
229.It Dv TCSANOW
230The change occurs immediately.
231.It Dv TCSADRAIN
232The change occurs after all output written to
233.Fa fd
234has been transmitted to the terminal.
235This value of
236.Fa action
237should be used when changing parameters that affect output.
238.It Dv TCSAFLUSH
239The change occurs after all output written to
240.Fa fd
241has been transmitted to the terminal.
242Additionally, any input that has been received but not read is discarded.
243.It Dv TCSASOFT
244If this value is
245.Em or Ns 'ed
246into the
247.Fa action
248value, the values of the
249.Em c_cflag ,
250.Em c_ispeed ,
251and
252.Em c_ospeed
253fields are ignored.
254.El
255.Pp
256The 0 baud rate is used to terminate the connection.
257If 0 is specified as the output speed to the function
258.Fn tcsetattr ,
259modem control will no longer be asserted on the terminal, disconnecting
260the terminal.
261.Pp
262If zero is specified as the input speed to the function
263.Fn tcsetattr ,
264the input baud rate will be set to the same value as that specified by
265the output baud rate.
266.Pp
267If
268.Fn tcsetattr
269is unable to make any of the requested changes, it returns -1 and
270sets
271.Va 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
331and
332.Fn cfsetspeed
333functions,
334as well as the
335.Dv TCSASOFT
336option to the
337.Fn tcsetattr
338function are extensions to the
339.St -p1003.1-88
340specification.
341