1TCGETATTR(3P)              POSIX Programmer's Manual             TCGETATTR(3P)
2
3
4

PROLOG

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

NAME

12       tcgetattr - get the parameters associated with the terminal
13

SYNOPSIS

15       #include <termios.h>
16
17       int tcgetattr(int fildes, struct termios *termios_p);
18
19

DESCRIPTION

21       The tcgetattr() function shall get the parameters associated  with  the
22       terminal  referred to by fildes and store them in the termios structure
23       referenced by termios_p.  The fildes argument is an open file  descrip‐
24       tor associated with a terminal.
25
26       The termios_p argument is a pointer to a termios structure.
27
28       The tcgetattr() operation is allowed from any process.
29
30       If  the terminal device supports different input and output baud rates,
31       the baud rates stored in the termios structure returned by  tcgetattr()
32       shall reflect the actual baud rates, even if they are equal. If differ‐
33       ing baud rates are not supported, the rate returned as the output  baud
34       rate  shall  be  the  actual baud rate. If the terminal device does not
35       support split baud rates, the input baud rate  stored  in  the  termios
36       structure shall be the output rate (as one of the symbolic values).
37

RETURN VALUE

39       Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
40       returned and errno set to indicate the error.
41

ERRORS

43       The tcgetattr() function shall fail if:
44
45       EBADF  The fildes argument is not a valid file descriptor.
46
47       ENOTTY The file associated with fildes is not a terminal.
48
49
50       The following sections are informative.
51

EXAMPLES

53       None.
54

APPLICATION USAGE

56       None.
57

RATIONALE

59       Care must be taken when changing the terminal attributes.  Applications
60       should  always  do  a  tcgetattr(),  save  the termios structure values
61       returned, and then  do  a  tcsetattr(),  changing  only  the  necessary
62       fields.  The  application  should  use  the values saved from the tcge‐
63       tattr() to reset the terminal state whenever it is done with the termi‐
64       nal.  This is necessary because terminal attributes apply to the under‐
65       lying port and not to each individual open instance; that is, all  pro‐
66       cesses that have used the terminal see the latest attribute changes.
67
68       A program that uses these functions should be written to catch all sig‐
69       nals and take other appropriate actions to ensure that when the program
70       terminates,  whether  planned  or  not,  the terminal device's state is
71       restored to its original state.
72
73       Existing practice dealing with  error  returns  when  only  part  of  a
74       request  can  be  honored is based on calls to the ioctl() function. In
75       historical BSD and System V implementations, the corresponding  ioctl()
76       returns  zero  if the requested actions were semantically correct, even
77       if some of the requested changes  could  not  be  made.  Many  existing
78       applications assume this behavior and would no longer work correctly if
79       the return value were changed from zero to -1 in this case.
80
81       Note that either specification has a problem. When zero is returned, it
82       implies everything succeeded even if some of the changes were not made.
83       When -1 is returned, it implies everything failed even though  some  of
84       the changes were made.
85
86       Applications  that need all of the requested changes made to work prop‐
87       erly should follow tcsetattr() with a call to tcgetattr()  and  compare
88       the appropriate field values.
89

FUTURE DIRECTIONS

91       None.
92

SEE ALSO

94       tcsetattr(), the Base Definitions volume of IEEE Std 1003.1-2001, Chap‐
95       ter 11, General Terminal Interface, <termios.h>
96
98       Portions of this text are reprinted and reproduced in  electronic  form
99       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
100       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
101       Specifications  Issue  6,  Copyright  (C) 2001-2003 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
109
110IEEE/The Open Group                  2003                        TCGETATTR(3P)
Impressum