1TCGETATTR(3P) POSIX Programmer's Manual TCGETATTR(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
12 tcgetattr — get the parameters associated with the terminal
13
15 #include <termios.h>
16
17 int tcgetattr(int fildes, struct termios *termios_p);
18
20 The tcgetattr() function shall get the parameters associated with the
21 terminal referred to by fildes and store them in the termios structure
22 referenced by termios_p. The fildes argument is an open file descrip‐
23 tor associated with a terminal.
24
25 The termios_p argument is a pointer to a termios structure.
26
27 The tcgetattr() operation is allowed from any process.
28
29 If the terminal device supports different input and output baud rates,
30 the baud rates stored in the termios structure returned by tcgetattr()
31 shall reflect the actual baud rates, even if they are equal. If differ‐
32 ing baud rates are not supported, the rate returned as the output baud
33 rate shall be the actual baud rate. If the terminal device does not
34 support split baud rates, the input baud rate stored in the termios
35 structure shall be the output rate (as one of the symbolic values).
36
38 Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
39 returned and errno set to indicate the error.
40
42 The tcgetattr() function shall fail if:
43
44 EBADF The fildes argument is not a valid file descriptor.
45
46 ENOTTY The file associated with fildes is not a terminal.
47
48 The following sections are informative.
49
51 None.
52
54 None.
55
57 Care must be taken when changing the terminal attributes. Applications
58 should always do a tcgetattr(), save the termios structure values
59 returned, and then do a tcsetattr(), changing only the necessary
60 fields. The application should use the values saved from the tcge‐
61 tattr() to reset the terminal state whenever it is done with the termi‐
62 nal. This is necessary because terminal attributes apply to the under‐
63 lying port and not to each individual open instance; that is, all pro‐
64 cesses that have used the terminal see the latest attribute changes.
65
66 A program that uses these functions should be written to catch all sig‐
67 nals and take other appropriate actions to ensure that when the program
68 terminates, whether planned or not, the terminal device's state is
69 restored to its original state.
70
71 Existing practice dealing with error returns when only part of a
72 request can be honored is based on calls to the ioctl() function. In
73 historical BSD and System V implementations, the corresponding ioctl()
74 returns zero if the requested actions were semantically correct, even
75 if some of the requested changes could not be made. Many existing
76 applications assume this behavior and would no longer work correctly if
77 the return value were changed from zero to -1 in this case.
78
79 Note that either specification has a problem. When zero is returned, it
80 implies everything succeeded even if some of the changes were not made.
81 When -1 is returned, it implies everything failed even though some of
82 the changes were made.
83
84 Applications that need all of the requested changes made to work prop‐
85 erly should follow tcsetattr() with a call to tcgetattr() and compare
86 the appropriate field values.
87
89 None.
90
92 tcsetattr()
93
94 The Base Definitions volume of POSIX.1‐2017, Chapter 11, General Termi‐
95 nal Interface, <termios.h>
96
98 Portions of this text are reprinted and reproduced in electronic form
99 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
100 table Operating System Interface (POSIX), The Open Group Base Specifi‐
101 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
102 Electrical and Electronics Engineers, Inc and The Open Group. In the
103 event of any discrepancy between this version and the original IEEE and
104 The Open Group Standard, the original IEEE and The Open Group Standard
105 is the referee document. The original Standard can be obtained online
106 at http://www.opengroup.org/unix/online.html .
107
108 Any typographical or formatting errors that appear in this page are
109 most likely to have been introduced during the conversion of the source
110 files to man page format. To report such errors, see https://www.ker‐
111 nel.org/doc/man-pages/reporting_bugs.html .
112
113
114
115IEEE/The Open Group 2017 TCGETATTR(3P)