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 arrayc_ccfor 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#ifpreprocessing directives, and they shall be distinct β except that theVMINandVTIMEsubscripts may have the same values as theVEOFandVEOLsubscripts, 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 symbolsCS7,CS8,CSTOPB,PARODD, andPARENB. 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β sendSIGTTOUfor 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
π COPYRIGHT π
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 π
π¦ 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