1TCSETATTR(3P) POSIX Programmer's Manual TCSETATTR(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 tcsetattr — set the parameters associated with the terminal
14
16 #include <termios.h>
17
18 int tcsetattr(int fildes, int optional_actions,
19 const struct termios *termios_p);
20
22 The tcsetattr() function shall set the parameters associated with the
23 terminal referred to by the open file descriptor fildes (an open file
24 descriptor associated with a terminal) from the termios structure ref‐
25 erenced by termios_p as follows:
26
27 * If optional_actions is TCSANOW, the change shall occur immediately.
28
29 * If optional_actions is TCSADRAIN, the change shall occur after all
30 output written to fildes is transmitted. This function should be
31 used when changing parameters that affect output.
32
33 * If optional_actions is TCSAFLUSH, the change shall occur after all
34 output written to fildes is transmitted, and all input so far
35 received but not read shall be discarded before the change is made.
36
37 If the output baud rate stored in the termios structure pointed to by
38 termios_p is the zero baud rate, B0, the modem control lines shall no
39 longer be asserted. Normally, this shall disconnect the line.
40
41 If the input baud rate stored in the termios structure pointed to by
42 termios_p is 0, the input baud rate given to the hardware is the same
43 as the output baud rate stored in the termios structure.
44
45 The tcsetattr() function shall return successfully if it was able to
46 perform any of the requested actions, even if some of the requested
47 actions could not be performed. It shall set all the attributes that
48 the implementation supports as requested and leave all the attributes
49 not supported by the implementation unchanged. If no part of the
50 request can be honored, it shall return −1 and set errno to [EINVAL].
51 If the input and output baud rates differ and are a combination that is
52 not supported, neither baud rate shall be changed. A subsequent call to
53 tcgetattr() shall return the actual state of the terminal device
54 (reflecting both the changes made and not made in the previous tcse‐
55 tattr() call). The tcsetattr() function shall not change the values
56 found in the termios structure under any circumstances.
57
58 The effect of tcsetattr() is undefined if the value of the termios
59 structure pointed to by termios_p was not derived from the result of a
60 call to tcgetattr() on fildes; an application should modify only fields
61 and flags defined by this volume of POSIX.1‐2008 between the call to
62 tcgetattr() and tcsetattr(), leaving all other fields and flags unmodi‐
63 fied.
64
65 No actions defined by this volume of POSIX.1‐2008, other than a call to
66 tcsetattr(), a close of the last file descriptor in the system associ‐
67 ated with this terminal device, or an open of the first file descriptor
68 in the system associated with this terminal device (using the
69 O_TTY_INIT flag if it is non-zero and the device is not a pseudo-termi‐
70 nal), shall cause any of the terminal attributes defined by this volume
71 of POSIX.1‐2008 to change.
72
73 If tcsetattr() is called from a process which is a member of a back‐
74 ground process group on a fildes associated with its controlling termi‐
75 nal:
76
77 * If the calling thread is blocking SIGTTOU signals or the process is
78 ignoring SIGTTOU signals, the operation completes normally and no
79 signal is sent.
80
81 * Otherwise, a SIGTTOU signal shall be sent to the process group.
82
84 Upon successful completion, 0 shall be returned. Otherwise, −1 shall be
85 returned and errno set to indicate the error.
86
88 The tcsetattr() function shall fail if:
89
90 EBADF The fildes argument is not a valid file descriptor.
91
92 EINTR A signal interrupted tcsetattr().
93
94 EINVAL The optional_actions argument is not a supported value, or an
95 attempt was made to change an attribute represented in the
96 termios structure to an unsupported value.
97
98 EIO The process group of the writing process is orphaned, the call‐
99 ing thread is not blocking SIGTTOU, and the process is not
100 ignoring SIGTTOU.
101
102 ENOTTY The file associated with fildes is not a terminal.
103
104 The following sections are informative.
105
107 None.
108
110 If trying to change baud rates, applications should call tcsetattr()
111 then call tcgetattr() in order to determine what baud rates were actu‐
112 ally selected.
113
114 In general, there are two reasons for an application to change the
115 parameters associated with a terminal device:
116
117 1. The device already has working parameter settings but the applica‐
118 tion needs a different behavior, such as non-canonical mode instead
119 of canonical mode. The application sets (or clears) only a few
120 flags or c_cc[] values. Typically, the terminal device in this case
121 is either the controlling terminal for the process or a pseudo-ter‐
122 minal.
123
124 2. The device is a modem or similar piece of equipment connected by a
125 serial line, and it was not open before the application opened it.
126 In this case, the application needs to initialize all of the param‐
127 eter settings ``from scratch''. However, since the termios struc‐
128 ture may include both standard and non-standard parameters, the
129 application cannot just initialize the whole structure in an arbi‐
130 trary way (e.g., using memset()) as this may cause some of the non-
131 standard parameters to be set incorrectly, resulting in non-con‐
132 forming behavior of the terminal device. Conversely, the applica‐
133 tion cannot just set the standard parameters, assuming that the
134 non-standard parameters will already have suitable values, as the
135 device might previously have been used with non-conforming parame‐
136 ter settings (and some implementations retain the settings from one
137 use to the next). The solution is to open the terminal device using
138 the O_TTY_INIT flag to initialize the terminal device to have con‐
139 forming parameter settings, obtain those settings using tcge‐
140 tattr(), and then set all of the standard parameters to the desired
141 settings.
142
144 The tcsetattr() function can be interrupted in the following situa‐
145 tions:
146
147 * It is interrupted while waiting for output to drain.
148
149 * It is called from a process in a background process group and SIGT‐
150 TOU is caught.
151
152 See also the RATIONALE section in tcgetattr().
153
155 Using an input baud rate of 0 to set the input rate equal to the output
156 rate may not necessarily be supported in a future version of this vol‐
157 ume of POSIX.1‐2008.
158
160 cfgetispeed(), tcgetattr()
161
162 The Base Definitions volume of POSIX.1‐2008, Chapter 11, General Termi‐
163 nal Interface, <termios.h>
164
166 Portions of this text are reprinted and reproduced in electronic form
167 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
168 -- Portable Operating System Interface (POSIX), The Open Group Base
169 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
170 cal and Electronics Engineers, Inc and The Open Group. (This is
171 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
172 event of any discrepancy between this version and the original IEEE and
173 The Open Group Standard, the original IEEE and The Open Group Standard
174 is the referee document. The original Standard can be obtained online
175 at http://www.unix.org/online.html .
176
177 Any typographical or formatting errors that appear in this page are
178 most likely to have been introduced during the conversion of the source
179 files to man page format. To report such errors, see https://www.ker‐
180 nel.org/doc/man-pages/reporting_bugs.html .
181
182
183
184IEEE/The Open Group 2013 TCSETATTR(3P)