tcsetattr(3)

โœจ tcgetattr, tcsetattr โ€” get & set terminal attributes โœจ

okay bestie, welcome to the tcsetattr(3) page, aka the part of libc that lets you โœจrearrange the vibesโœจ of your terminal. no cap. ๐ŸŽ€


๐Ÿ“š LIBRARY

Standard C library (that's libc, link with -lc) ๐Ÿ’–


๐Ÿฆ‹ SYNOPSIS

#include <termios.h>

int tcgetattr(int fd, struct termios *termios_p);
int tcsetattr(int fd, int optional_actions,
              const struct termios *termios_p);

๐Ÿ’… DESCRIPTION

tcgetattr() โ€” the read girlie ๐ŸŒธ

tcgetattr() gets the parameters associated with the object referred by fd, and stores them in the termios structure referenced by termios_p. it's giving "let me see what you're working with."

lowkey important: this function may be invoked from a background process ๐Ÿ‘€ โ€” however, the terminal attributes may be subsequently changed by a foreground process. so like, you got the tea, but someone in the front row might spill it. ๐Ÿซ 

tcsetattr() โ€” the set girlie ๐Ÿ‘‘

tcsetattr() sets the parameters associated with the terminal (unless support is required from the underlying hardware that is not available) from the termios structure referred to by termios_p. basically: request submitted, but if the hardware can't do it, bestie, it just can't. ๐Ÿ™ˆ

and optional_actions specifies when the changes take effect, which is the main character decision of this whole function:

  • TCSANOW โ€” the change occurs immediately. no waiting, no thoughts, just pure yolo energy. ๐Ÿ’…
  • TCSADRAIN โ€” the change occurs after all output written to fd has been transmitted. this option should be used when changing parameters that affect output. like, let the words finish leaving the group chat first. โœจ
  • TCSAFLUSH โ€” the change occurs after all output written to the object referred by fd has been transmitted, and all input that has been received but not read will be discarded before the change is made. so it waits for the outbox to send, then it clears the unread messages. ๐Ÿ˜ญ iconic, honestly.

๐ŸŒˆ RETURN VALUE

  • 0 โ€” on success. slay. ๐ŸŽ‰
  • -1 โ€” on failure, and it sets errno to indicate the error. not slay. ๐Ÿ’€

๐Ÿงš ATTRIBUTES

for an explanation of the terms used in this section, see attributes(7). (yes we're citing our sources, academic queen ๐Ÿ‘‘)

  • Interface: tcgetattr(), tcsetattr()
    • Attribute: Thread safety
    • Value: MT-Safe

periodt. โœจ


โญ STANDARDS

POSIX.1-2008. ๐Ÿ†


๐Ÿ•ฐ๏ธ HISTORY

POSIX.1-2001. it's been around, and it's been serving. ๐Ÿ’œ


โš ๏ธ CAVEATS

okay this one is the important one, so listen up bestie, no skimming:

tcsetattr() returns success if any of the requested changes could be successfully carried out.

read that again. any. not all. so the function can come back looking all happy and successful while some of your changes lowkey ghosted you. ๐Ÿ˜ญ therefore, when making multiple changes, it may be necessary to follow this call with a further call to tcgetattr() to check that all changes have been performed successfully. always double-check, queen โ€” trust but verify. ๐Ÿซถ


๐Ÿ‘€ SEE ALSO


and that's the whole vibe check, babe. this page is from Linux man-pages 6.20, dated 2026-07-02, and it's the tcsetattr(3) moment. go forth and set your terminal attributes responsibly. mwah. ๐Ÿ’‹๐ŸŽ€โœจ

๐Ÿ“ฆ where this page comes from
  • 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 6.20
  • ๐Ÿ“œ the page's license: GPL-2.0-or-later
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms