Debian Codegraph @

upstream/debian-unstable/man2/TCSETS.2const

raw
1 .\" Copyright 2002, Walter Harms <[email protected]>
2 .\" Copyright 2002, Andries E. Brouwer <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: GPL-1.0-or-later
6 .\"
7 .TH TCSETS 2const 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 TCGETS,
10 TCSETS,
11 TCSETSW,
12 TCSETSF,
13 TCGETS2,
14 TCSETS2,
15 TCSETSW2,
16 TCSETSF2,
17 TCGETA,
18 TCSETA,
19 TCSETAW,
20 TCSETAF
21 \-
22 get and set terminal attributes
23 .SH LIBRARY
24 Standard C library
25 .RI ( libc ,\~ \-lc )
26 .SH SYNOPSIS
27 .nf
28 .BR "#include <asm/termbits.h>" " /* Definition of " TC* " constants */"
29 .B #include <sys/ioctl.h>
30 .P
31 .BI "int ioctl(int " fd ", TCGETS, struct termios *" argp );
32 .BI "int ioctl(int " fd ", TCSETS, const struct termios *" argp );
33 .BI "int ioctl(int " fd ", TCSETSW, const struct termios *" argp );
34 .BI "int ioctl(int " fd ", TCSETSF, const struct termios *" argp );
35 .P
36 .BI "int ioctl(int " fd ", TCGETS2, struct termios2 *" argp );
37 .BI "int ioctl(int " fd ", TCSETS2, const struct termios2 *" argp );
38 .BI "int ioctl(int " fd ", TCSETSW2, const struct termios2 *" argp );
39 .BI "int ioctl(int " fd ", TCSETSF2, const struct termios2 *" argp );
40 .P
41 .BI "[[deprecated]] int ioctl(int " fd ", TCGETA, struct termio *" argp );
42 .BI "[[deprecated]] int ioctl(int " fd ", TCSETA, const struct termio *" argp );
43 .BI "[[deprecated]] int ioctl(int " fd ", TCSETAW, const struct termio *" argp );
44 .BI "[[deprecated]] int ioctl(int " fd ", TCSETAF, const struct termio *" argp );
45 .P
46 .B #include <asm/termbits.h>
47 .P
48 .B struct termios;
49 .B struct termios2;
50 .B struct [[deprecated]] termio;
51 .fi
52 .SH DESCRIPTION
53 .TP
54 .B TCGETS
55 Equivalent to
56 .IR "tcgetattr(fd, argp)" .
57 .IP
58 Get the current serial port settings.
59 .TP
60 .B TCSETS
61 Equivalent to
62 .IR "tcsetattr(fd, TCSANOW, argp)" .
63 .IP
64 Set the current serial port settings.
65 .TP
66 .B TCSETSW
67 Equivalent to
68 .IR "tcsetattr(fd, TCSADRAIN, argp)" .
69 .IP
70 Allow the output buffer to drain, and
71 set the current serial port settings.
72 .TP
73 .B TCSETSF
74 Equivalent to
75 .IR "tcsetattr(fd, TCSAFLUSH, argp)" .
76 .IP
77 Allow the output buffer to drain, discard pending input, and
78 set the current serial port settings.
79 .P
80 The following four ioctls
81 are just like
82 .BR TCGETS ,
83 .BR TCSETS ,
84 .BR TCSETSW ,
85 .BR TCSETSF ,
86 except that they take a
87 .I "struct termios2\~*"
88 instead of a
89 .IR "struct termios\~*" .
90 If the structure member
91 .B c_cflag
92 contains the flag
93 .BR BOTHER ,
94 then the baud rate is stored in the structure members
95 .B c_ispeed
96 and
97 .B c_ospeed
98 as integer values.
99 These ioctls are not supported on all architectures.
100 .RS
101 .TP
102 .B TCGETS2
103 .TQ
104 .B TCSETS2
105 .TQ
106 .B TCSETSW2
107 .TQ
108 .B TCSETSF2
109 .RE
110 .P
111 The following four ioctls are just like
112 .BR TCGETS ,
113 .BR TCSETS ,
114 .BR TCSETSW ,
115 .BR TCSETSF ,
116 except that they take a
117 .I "struct termio\~*"
118 instead of a
119 .IR "struct termios\~*" .
120 .RS
121 .TP
122 .B TCGETA
123 .TQ
124 .B TCSETA
125 .TQ
126 .B TCSETAW
127 .TQ
128 .B TCSETAF
129 .RE
130 .SH RETURN VALUE
131 On success,
132 0 is returned.
133 On error, \-1 is returned and
134 .I errno
135 is set to indicate the error.
136 .SH ERRORS
137 .TP
138 .B EPERM
139 Insufficient permission.
140 .SH HISTORY
141 .TP
142 .B TCGETS2
143 .TQ
144 .B TCSETS2
145 .TQ
146 .B TCSETSW2
147 .TQ
148 .B TCSETSF2
149 .\" linux.git commit 64bb6c5e1ddcd47c951740485026ef08975ee2e6
150 .\" linux.git commit 592ee3a5e5e2a981ef2829a0380093006d045661
151 Linux 2.6.20.
152 .SH CAVEATS
153 .B struct termios
154 from
155 .I <asm/termbits.h>
156 is different and incompatible with
157 .B struct termios
158 from
159 .IR <termios.h> .
160 These ioctl calls require
161 .B struct termios
162 from
163 .IR <asm/termbits.h> .
164 .SH EXAMPLES
165 Get or set arbitrary baudrate on the serial port.
166 .P
167 .\" SRC BEGIN (tcgets.c)
168 .EX
169 /* SPDX-License-Identifier: GPL-2.0-or-later */
170 \&
171 #include <asm/termbits.h>
172 #include <fcntl.h>
173 #include <stdio.h>
174 #include <stdlib.h>
175 #include <sys/ioctl.h>
176 #include <unistd.h>
177 \&
178 int
179 main(int argc, char *argv[])
180 {
181 #if !defined BOTHER
182 fprintf(stderr, "BOTHER is unsupported\[rs]n");
183 /* Program may fallback to TCGETS/TCSETS with Bnnn constants */
184 exit(EXIT_FAILURE);
185 #else
186 /* Declare tio structure, its type depends on supported ioctl */
187 # if defined TCGETS2
188 struct termios2 tio;
189 # else
190 struct termios tio;
191 # endif
192 int fd, rc;
193 \&
194 if (argc != 2 && argc != 3 && argc != 4) {
195 fprintf(stderr, "Usage: %s device [output [input] ]\[rs]n", argv[0]);
196 exit(EXIT_FAILURE);
197 }
198 \&
199 fd = open(argv[1], O_RDWR | O_NONBLOCK | O_NOCTTY);
200 if (fd < 0) {
201 perror("open");
202 exit(EXIT_FAILURE);
203 }
204 \&
205 /* Get the current serial port settings via supported ioctl */
206 # if defined TCGETS2
207 rc = ioctl(fd, TCGETS2, &tio);
208 # else
209 rc = ioctl(fd, TCGETS, &tio);
210 # endif
211 if (rc) {
212 perror("TCGETS");
213 close(fd);
214 exit(EXIT_FAILURE);
215 }
216 \&
217 /* Change baud rate when more arguments were provided */
218 if (argc == 3 || argc == 4) {
219 /* Clear the current output baud rate and fill a new value */
220 tio.c_cflag &= \[ti]CBAUD;
221 tio.c_cflag |= BOTHER;
222 tio.c_ospeed = atoi(argv[2]);
223 \&
224 /* Clear the current input baud rate and fill a new value */
225 tio.c_cflag &= \[ti](CBAUD << IBSHIFT);
226 tio.c_cflag |= BOTHER << IBSHIFT;
227 /* When 4th argument is not provided reuse output baud rate */
228 tio.c_ispeed = (argc == 4) ? atoi(argv[3]) : atoi(argv[2]);
229 \&
230 /* Set new serial port settings via supported ioctl */
231 # if defined TCSETS2
232 rc = ioctl(fd, TCSETS2, &tio);
233 # else
234 rc = ioctl(fd, TCSETS, &tio);
235 # endif
236 if (rc) {
237 perror("TCSETS");
238 close(fd);
239 exit(EXIT_FAILURE);
240 }
241 \&
242 /* And get new values which were really configured */
243 # if defined TCGETS2
244 rc = ioctl(fd, TCGETS2, &tio);
245 # else
246 rc = ioctl(fd, TCGETS, &tio);
247 # endif
248 if (rc) {
249 perror("TCGETS");
250 close(fd);
251 exit(EXIT_FAILURE);
252 }
253 }
254 \&
255 close(fd);
256 \&
257 printf("output baud rate: %u\[rs]n", tio.c_ospeed);
258 printf("input baud rate: %u\[rs]n", tio.c_ispeed);
259 \&
260 exit(EXIT_SUCCESS);
261 #endif
262 }
263 .EE
264 .\" SRC END
265 .SH SEE ALSO
266 .BR ioctl (2),
267 .BR ioctl_tty (2),
268 .BR termios (3)