termios.h(7POSIX)

🌸 termios.h β€” PROLOG ✨

okay bestie, real talk before we even start: this page is from the POSIX Programmer's Manual, specifically termios.h(7POSIX). πŸ’–

Heads up though β€” the Linux implementation of this interface may differ from what's written here (so go check the corresponding Linux manual page for the actual Linux behavior, mkay?), or the interface may not even be implemented on Linux at all. πŸ’€ Not trying to scare you, just keeping it real.

πŸ‘‘ NAME

termios.h β€” define values for termios. That's it, that's the whole vibe. πŸ’…


🌈 SYNOPSIS

#include <termios.h>

πŸ¦‹ DESCRIPTION

So the <termios.h> header is gonna contain all the definitions that the terminal I/O interfaces use. (If you want the actual structures and names, go look at Chapter 11, General Terminal Interface. iykyk.)

πŸŽ€ The termios Structure

The <termios.h> header shall define these data types through typedef:

  • cc_t β€” used for terminal special characters. πŸ“
  • speed_t β€” used for terminal baud rates. ⚑
  • tcflag_t β€” used for terminal modes. πŸŽ›οΈ

All three of those types shall be unsigned integer types. Periodt.

The implementation shall support one or more programming environments where the widths of cc_t, speed_t, and tcflag_t are no greater than the width of type long. Wanna know the names of those programming environments? You can get them with the confstr() function or the getconf utility. 🫢

The <termios.h> header shall define the termios structure, which shall include at least these members:

tcflag_t  c_iflag     Input modes.
tcflag_t  c_oflag     Output modes.
tcflag_t  c_cflag     Control modes.
tcflag_t  c_lflag     Local modes.
cc_t      c_cc[NCCS]  Control characters.

And the header shall define this symbolic constant:

  • NCCS β€” the size of the array c_cc for control characters. ✨

The <termios.h> header shall also define these symbolic constants for use as subscripts for the array c_cc. Here's the whole cast of characters, and which mode they show up in (canonical, non-canonical, or both πŸ‘€):

  • VEOF β€” canonical mode β€” EOF character. 🌸
  • VEOL β€” canonical mode β€” EOL character.
  • VERASE β€” canonical mode β€” ERASE character.
  • VINTR β€” canonical mode and non-canonical mode β€” INTR character. πŸ”₯
  • VKILL β€” canonical mode β€” KILL character.
  • VMIN β€” non-canonical mode β€” MIN value.
  • VQUIT β€” canonical mode and non-canonical mode β€” QUIT character.
  • VSTART β€” canonical mode and non-canonical mode β€” START character.
  • VSTOP β€” canonical mode and non-canonical mode β€” STOP character.
  • VSUSP β€” canonical mode and non-canonical mode β€” SUSP character.
  • VTIME β€” non-canonical mode β€” TIME value. ⏳
The subscript values shall be suitable for use in #if preprocessing directives, and they shall be distinct β€” except that the VMIN and VTIME subscripts may have the same values as the VEOF and VEOL subscripts, respectively. So like, don't come for me about those two. πŸ’€

πŸ’œ Input Modes

The <termios.h> header shall define these symbolic constants for use as flags in the c_iflag field. The c_iflag field is the one that describes the basic terminal input control:

  • BRKINT β€” signal interrupt on break. 🚨
  • ICRNL β€” map CR to NL on input.
  • IGNBRK β€” ignore break condition.
  • IGNCR β€” ignore CR.
  • IGNPAR β€” ignore characters with parity errors.
  • INLCR β€” map NL to CR on input.
  • INPCK β€” enable input parity check.
  • ISTRIP β€” strip character.
  • IXANY β€” enable any character to restart output.
  • IXOFF β€” enable start/stop input control.
  • IXON β€” enable start/stop output control.
  • PARMRK β€” mark parity errors.

🌸 Output Modes

The <termios.h> header shall define these symbolic constants for use as flags in the c_oflag field. The c_oflag field specifies how the system treats output:

  • OPOST β€” post-process output.
  • ONLCR β€” map NL to CR-NL on output.
  • OCRNL β€” map CR to NL on output.
  • ONOCR β€” no CR output at column 0.
  • ONLRET β€” NL performs CR function.
  • OFDEL β€” fill is DEL.
  • OFILL β€” use fill characters for delay.
  • NLDLY β€” select newline delays:
    • NL0 β€” newline type 0.
    • NL1 β€” newline type 1.
  • CRDLY β€” select carriage-return delays:
    • CR0 β€” carriage-return delay type 0.
    • CR1 β€” carriage-return delay type 1.
    • CR2 β€” carriage-return delay type 2.
    • CR3 β€” carriage-return delay type 3.
  • TABDLY β€” select horizontal-tab delays:
    • TAB0 β€” horizontal-tab delay type 0.
    • TAB1 β€” horizontal-tab delay type 1.
    • TAB2 β€” horizontal-tab delay type 2.
    • TAB3 β€” expand tabs to spaces.
  • BSDLY β€” select backspace delays:
    • BS0 β€” backspace-delay type 0.
    • BS1 β€” backspace-delay type 1.
  • VTDLY β€” select vertical-tab delays:
    • VT0 β€” vertical-tab delay type 0.
    • VT1 β€” vertical-tab delay type 1.
  • FFDLY β€” select form-feed delays:
    • FF0 β€” form-feed delay type 0.
    • FF1 β€” form-feed delay type 1.

⚑ Baud Rate Selection

The <termios.h> header shall define these symbolic constants for use as values of objects of type speed_t.

So the input and output baud rates are stored in the termios structure, and these are the valid values for objects of type speed_t. That said β€” not all baud rates need be supported by the underlying hardware, bestie. Don't fight your serial port about it. 😭

  • B0 β€” hang up. πŸ“΄
  • B50 β€” 50 baud.
  • B75 β€” 75 baud.
  • B110 β€” 110 baud.
  • B134 β€” 134.5 baud.
  • B150 β€” 150 baud.
  • B200 β€” 200 baud.
  • B300 β€” 300 baud.
  • B600 β€” 600 baud.
  • B1200 β€” 1200 baud.
  • B1800 β€” 1800 baud.
  • B2400 β€” 2400 baud.
  • B4800 β€” 4800 baud.
  • B9600 β€” 9600 baud.
  • B19200 β€” 19200 baud.
  • B38400 β€” 38400 baud.

πŸŽ›οΈ Control Modes

The <termios.h> header shall define these symbolic constants for use as flags in the c_cflag field. The c_cflag field describes the hardware control of the terminal β€” and again, not all values specified are required to be supported by the underlying hardware. So manage your expectations, queen. πŸ’…

  • CSIZE β€” character size:
    • CS5 β€” 5 bits.
    • CS6 β€” 6 bits.
    • CS7 β€” 7 bits.
    • CS8 β€” 8 bits.
  • CSTOPB β€” send two stop bits, else one.
  • CREAD β€” enable receiver.
  • PARENB β€” parity enable.
  • PARODD β€” odd parity, else even.
  • HUPCL β€” hang up on last close.
  • CLOCAL β€” ignore modem status lines.
The implementation shall support the functionality associated with the symbols CS7, CS8, CSTOPB, PARODD, and PARENB. Those five are the non-negotiables, fr fr. πŸ”₯

πŸ’– Local Modes

The <termios.h> header shall define these symbolic constants for use as flags in the c_lflag field. The c_lflag field of the argument structure is what controls all the various terminal functions:

  • ECHO β€” enable echo.
  • ECHOE β€” echo erase character as error-correcting backspace.
  • ECHOK β€” echo KILL.
  • ECHONL β€” echo NL.
  • ICANON β€” canonical input (erase and kill processing).
  • IEXTEN β€” enable extended input character processing.
  • ISIG β€” enable signals.
  • NOFLSH β€” disable flush after interrupt or quit.
  • TOSTOP β€” send SIGTTOU for background output. 🚨

✨ Attribute Selection

The <termios.h> header shall define these symbolic constants for use with tcsetattr():

  • TCSANOW β€” change attributes immediately.
  • TCSADRAIN β€” change attributes when output has drained.
  • TCSAFLUSH β€” change attributes when output has drained; also flush pending input.

🌈 Line Control

The <termios.h> header shall define these symbolic constants for use with tcflush():

  • TCIFLUSH β€” flush pending input.
  • TCIOFLUSH β€” flush both pending input and untransmitted output.
  • TCOFLUSH β€” flush untransmitted output.

And the <termios.h> header shall define these symbolic constants for use with tcflow():

  • TCIOFF β€” transmit a STOP character, intended to suspend input data.
  • TCION β€” transmit a START character, intended to restart input data.
  • TCOOFF β€” suspend output.
  • TCOON β€” restart output.

The <termios.h> header shall define the pid_t type as described in <sys/types.h>.

The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided. 🫢

speed_t cfgetispeed(const struct termios *);
speed_t cfgetospeed(const struct termios *);
int     cfsetispeed(struct termios *, speed_t);
int     cfsetospeed(struct termios *, speed_t);
int     tcdrain(int);
int     tcflow(int, int);
int     tcflush(int, int);
int     tcgetattr(int, struct termios *);
pid_t   tcgetsid(int);
int     tcsendbreak(int, int);
int     tcsetattr(int, int, const struct termios *);

The following sections are informative. πŸ‘€ (Yes bestie, informative β€” meaning they're the lore, not the law.)


🧚 APPLICATION USAGE

These names are reserved for XSI-conformant systems to use as an extension to everything above. So strictly conforming applications shall not use them. Hands off, okay? πŸ™ˆ

CBAUD      EXTB       VDSUSP
DEFECHO    FLUSHO     VLNEXT
ECHOCTL    LOBLK      VREPRINT
ECHOKE     PENDIN     VSTATUS
ECHOPRT    SWTCH      VWERASE
EXTA       VDISCARD

πŸ’€ RATIONALE

None.

(Not me expecting a whole essay and getting nothing. Iconic minimalism honestly.) ✨


πŸ¦‹ FUTURE DIRECTIONS

None.


πŸ”₯ SEE ALSO

  • <sys_types.h>

The System Interfaces volume of POSIX.1‐2017: cfgetispeed(), cfgetospeed(), cfsetispeed(), cfsetospeed(), confstr(), tcdrain(), tcflow(), tcflush(), tcgetattr(), tcgetsid(), tcsendbreak(), tcsetattr()

The Shell and Utilities volume of POSIX.1‐2017: Chapter 11, General Terminal Interface, getconf

Okay bestie, legal era incoming, but it's short I promise 🫢

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. Like, the whole glow-up was borrowed from them, no cap.

And listen β€” if this version and the original IEEE / The Open Group Standard ever beef, the original IEEE and The Open Group Standard is the referee document. Periodt. It wins, every time, no debate πŸ’…

Wanna read the actual source of truth? 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. It's giving "glow-up gone slightly sideways" 😭 β€” not the original authors' fault, fr fr.

To report such errors, see:

https://www.kernel.org/doc/man-pages/reporting_bugs.html
Bestie, if you spot a typo, don't just vibe with it β€” go report it. The maintainers will literally thank you πŸ™ˆ

And that's a wrap on termios.h(7POSIX), bestie!! βœ¨πŸ¦‹ You made it all the way to the legal section, which is main character energy honestly πŸ‘‘ This page comes to you from IEEE/The Open Group, 2017 β€” so go forth, configure your terminals, and stay iconic πŸŒΈπŸ’œ

the end, mwah πŸ’‹