TCGETATTR(3P)
π TCGETATTR(3P) β bestie edition π
okay so this one lives in the POSIX Programmer's Manual, and it's called tcgetattr. yes it's giving "terminal girlie" and honestly? iconic.
β οΈ heads up babes: this page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so go peek at the corresponding Linux manual page for the Linux deets), 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 πΈ
okay so tcgetattr() shall get the parameters associated with the terminal referred to by fildes and store them in the termios structure referenced by termios_p. simple as that. π
the fildes argument is an open file descriptor associated with a terminal.
the termios_p argument is a pointer to a termios structure.
and the best part? the tcgetattr() operation is allowed from any process. no gatekeeping, we love that for us. π
now, baud rate tea β β 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). periodt. β¨
π RETURN VALUE π
- upon successful completion,
0shall be returned π«Ά - otherwise,
-1shall be returned anderrnoset to indicate the error π
π₯ ERRORS π₯
the tcgetattr() function shall fail if:
EBADFβ thefildesargument is not a valid file descriptor. not a real one bestie πENOTTYβ the file associated withfildesis not a terminal. wrong vibe, wrong file π«
the following sections are informative. (aka, lore, not law π )
π¦ EXAMPLES π¦
None. β yeah. nothing here. empty. a void. moving on π
π APPLICATION USAGE π
None. β also empty. the manpage said "no notes" and meant it. β¨
π RATIONALE π
okay so this part is important, 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. why?? 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 a shared vibe, not a private one. π
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. no leaving the terminal in a cursed state, bestie. π¨
now for the historical lore π: 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.
and 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
-1is returned, it implies everything failed even though some of the changes were made.
neither is giving flawless, tbh.
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. iykyk. π
β FUTURE DIRECTIONS β
None. β the future is undefined but in a chill way. π¦
π 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, we ate and left zero crumbs πβ¨ this cutie was brought to you by IEEE/The Open Group, dated 2017, and yes it's still TCGETATTR(3P) β slay, periodt, goodnight ππ
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms