TCGETATTR(3POSIX)
π TCGETATTR(3POSIX) β POSIX Programmer's Manual π
okay bestie, welcome to tcgetattr(3POSIX), straight out of the POSIX Programmer's Manual. this is the girlies' guide to reading your terminal's whole vibe, no cap. π
β¨ PROLOG β¨
so like, real talk first: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so go check the corresponding Linux manual page for the actual tea β), or the interface might not even be implemented on Linux at all. π
πΈ NAME πΈ
tcgetattr β get the parameters associated with the terminal
π¦ SYNOPSIS π¦
#include <termios.h>
int tcgetattr(int fildes, struct termios *termios_p);
π DESCRIPTION π
so the tcgetattr() function shall get the parameters associated with the terminal referred to by fildes and store them in the termios structure referenced by termios_p. the fildes argument is an open file descriptor associated with a terminal. π₯οΈβ¨
the termios_p argument is a pointer to a termios structure.
and here's the slay part: the tcgetattr() operation is allowed from any process. no gatekeeping. π
if the terminal device supports different input and output baud rates, the baud rates stored in the termios structure returned by tcgetattr() shall reflect the actual baud rates, even if they are equal. if differing baud rates are not supported, the rate returned as the output baud rate shall be the actual baud rate. and if the terminal device does not support split baud rates, the input baud rate stored in the termios structure shall be the output rate (as one of the symbolic values). it's giving "one rate fits both ports" fr fr. π«
π₯ RETURN VALUE π₯
upon successful completion, 0 shall be returned. otherwise, -1 shall be returned and errno set to indicate the error. that's it, that's the whole mood. π
π ERRORS π
the tcgetattr() function shall fail if:
EBADFβ thefildesargument is not a valid file descriptor.ENOTTYβ the file associated withfildesis not a terminal.
heads up bestie: the following sections are informative. they're the extra lore, not the rules. π
π EXAMPLES π
None. (yes literally, nothing here. moving on. πΆβοΈ)
π§ APPLICATION USAGE π§
None. (also nothing. iconic of them honestly. π)
π RATIONALE π
okay this part actually matters, so listen up. π«Ά
care must be taken when changing the terminal attributes. applications should always do a tcgetattr(), save the termios structure values returned, and then do a tcsetattr(), changing only the necessary fields. the application should use the values saved from the tcgetattr() to reset the terminal state whenever it is done with the terminal. this is necessary because terminal attributes apply to the underlying port and not to each individual open instance; that is, all processes that have used the terminal see the latest attribute changes. it's giving shared group chat, not DMs. π±
a program that uses these functions should be written to catch all signals and take other appropriate actions to ensure that when the program terminates, whether planned or not, the terminal device's state is restored to its original state. protect the terminal's peace at all costs. π‘οΈ
existing practice dealing with error returns when only part of a request can be honored is based on calls to the ioctl() function. in historical BSD and System V implementations, the corresponding ioctl() returns zero if the requested actions were semantically correct, even if some of the requested changes could not be made. many existing applications assume this behavior and would no longer work correctly if the return value were changed from zero to -1 in this case. legacy drama, we don't touch it. π
note that either specification has a problem. when zero is returned, it implies everything succeeded even if some of the changes were not made. when -1 is returned, it implies everything failed even though some of the changes were made. literally can't win. π
applications that need all of the requested changes made to work properly should follow tcsetattr() with a call to tcgetattr() and compare the appropriate field values. verify, don't assume. β
β FUTURE DIRECTIONS β
None.
π SEE ALSO π
tcsetattr()- the Base Definitions volume of POSIX.1β2017, Chapter 11, General Terminal Interface,
<termios.h>
π COPYRIGHT π
portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! brought to you by IEEE/The Open Group, dated 2017, for TCGETATTR(3POSIX). go read your terminal's parameters and stay hydrated. πβ¨π¦
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms