1TCSETATTR(P) POSIX Programmer's Manual TCSETATTR(P)
2
3
4
6 tcsetattr - set the parameters associated with the terminal
7
9 #include <termios.h>
10
11 int tcsetattr(int fildes, int optional_actions,
12 const struct termios *termios_p);
13
14
16 The tcsetattr() function shall set the parameters associated with the
17 terminal referred to by the open file descriptor fildes (an open file
18 descriptor associated with a terminal) from the termios structure ref‐
19 erenced by termios_p as follows:
20
21 * If optional_actions is TCSANOW, the change shall occur immediately.
22
23 * If optional_actions is TCSADRAIN, the change shall occur after all
24 output written to fildes is transmitted. This function should be
25 used when changing parameters that affect output.
26
27 * If optional_actions is TCSAFLUSH, the change shall occur after all
28 output written to fildes is transmitted, and all input so far
29 received but not read shall be discarded before the change is made.
30
31 If the output baud rate stored in the termios structure pointed to by
32 termios_p is the zero baud rate, B0, the modem control lines shall no
33 longer be asserted. Normally, this shall disconnect the line.
34
35 If the input baud rate stored in the termios structure pointed to by
36 termios_p is 0, the input baud rate given to the hardware is the same
37 as the output baud rate stored in the termios structure.
38
39 The tcsetattr() function shall return successfully if it was able to
40 perform any of the requested actions, even if some of the requested
41 actions could not be performed. It shall set all the attributes that
42 the implementation supports as requested and leave all the attributes
43 not supported by the implementation unchanged. If no part of the
44 request can be honored, it shall return -1 and set errno to [EINVAL].
45 If the input and output baud rates differ and are a combination that is
46 not supported, neither baud rate shall be changed. A subsequent call to
47 tcgetattr() shall return the actual state of the terminal device
48 (reflecting both the changes made and not made in the previous tcse‐
49 tattr() call). The tcsetattr() function shall not change the values
50 found in the termios structure under any circumstances.
51
52 The effect of tcsetattr() is undefined if the value of the termios
53 structure pointed to by termios_p was not derived from the result of a
54 call to tcgetattr() on fildes; an application should modify only fields
55 and flags defined by this volume of IEEE Std 1003.1-2001 between the
56 call to tcgetattr() and tcsetattr(), leaving all other fields and flags
57 unmodified.
58
59 No actions defined by this volume of IEEE Std 1003.1-2001, other than a
60 call to tcsetattr() or a close of the last file descriptor in the sys‐
61 tem associated with this terminal device, shall cause any of the termi‐
62 nal attributes defined by this volume of IEEE Std 1003.1-2001 to
63 change.
64
65 If tcsetattr() is called from a process which is a member of a back‐
66 ground process group on a fildes associated with its controlling termi‐
67 nal:
68
69 * If the calling process is blocking or ignoring SIGTTOU signals, the
70 operation completes normally and no signal is sent.
71
72 * Otherwise, a SIGTTOU signal shall be sent to the process group.
73
75 Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
76 returned and errno set to indicate the error.
77
79 The tcsetattr() function shall fail if:
80
81 EBADF The fildes argument is not a valid file descriptor.
82
83 EINTR A signal interrupted tcsetattr().
84
85 EINVAL The optional_actions argument is not a supported value, or an
86 attempt was made to change an attribute represented in the
87 termios structure to an unsupported value.
88
89 ENOTTY The file associated with fildes is not a terminal.
90
91
92 The tcsetattr() function may fail if:
93
94 EIO The process group of the writing process is orphaned, and the
95 writing process is not ignoring or blocking SIGTTOU.
96
97
98 The following sections are informative.
99
101 None.
102
104 If trying to change baud rates, applications should call tcsetattr()
105 then call tcgetattr() in order to determine what baud rates were actu‐
106 ally selected.
107
109 The tcsetattr() function can be interrupted in the following situa‐
110 tions:
111
112 * It is interrupted while waiting for output to drain.
113
114 * It is called from a process in a background process group and SIGT‐
115 TOU is caught.
116
117 See also the RATIONALE section in tcgetattr() .
118
120 Using an input baud rate of 0 to set the input rate equal to the output
121 rate may not necessarily be supported in a future version of this vol‐
122 ume of IEEE Std 1003.1-2001.
123
125 cfgetispeed() , tcgetattr() , the Base Definitions volume of
126 IEEE Std 1003.1-2001, Chapter 11, General Terminal Interface,
127 <termios.h>, <unistd.h>
128
130 Portions of this text are reprinted and reproduced in electronic form
131 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
132 -- Portable Operating System Interface (POSIX), The Open Group Base
133 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
134 Electrical and Electronics Engineers, Inc and The Open Group. In the
135 event of any discrepancy between this version and the original IEEE and
136 The Open Group Standard, the original IEEE and The Open Group Standard
137 is the referee document. The original Standard can be obtained online
138 at http://www.opengroup.org/unix/online.html .
139
140
141
142IEEE/The Open Group 2003 TCSETATTR(P)