get the current terminal control settings
#include <termios.h>
int tcgetattr( int fildes,
struct termios *termios_p );
The tcgetattr() function gets the current terminal control settings
for the opened device indicated by fildes, and
stores the results in the structure pointed to by termios_p.
The termios control structure is defined in
<termios.h>, and contains at least the members
described below.
- tcflag_t c_iflag
- Input modes. This member contains at least the following bits:
- BRKINT
- Signal interrupt on break.
- ICRNL
- Map CR to NL on input.
- IGNBRK
- Ignore break conditions.
- IGNCR
- Ignore CR.
- IGNPAR
- Ignore characters with parity errors.
- INLCR
- Map NL to CR on input.
- INPCK
- Enable input parity check.
- ISTRIP
- Strip top bit from character.
- IXOFF
- Enable software input flow control (via START/STOP chars).
- IXON
- Enable software output flow control (via START/STOP chars).
- PARMRK
- Mark parity errors in the input data stream.
- tcflag_t c_oflag
- Output modes. This member contains at least the following bits:
- OPOST
- Perform output processing.
- tcflag_t c_cflag
- Control modes. This member contains at least the following bits:
- CLOCAL
- Ignore modem status lines.
- CREAD
- Enable receiver.
- CSIZE
- Number of data bits per character.
- CS5
- 5 data bits
- CS6
- 6 data bits
- CS7
- 7 data bits
- CS8
- 8 data bits
- CSTOPB
- Two stop bits, else one.
- HUPCL
- Hang up on last close.
- PARENB
- Parity enable.
- PARODD
- Odd parity, else even.
The following bits will also have effect within the c_cflag
member if the IEXTEN bit of c_lflag is set:
- PARSTK
- Stick parity (mark parity if PARODD is set, else
space parity).
- IHFLOW
- Support input flow control using the hardware handshaking lines.
- OHFLOW
- Support output flow control using the hardware handshaking lines.
- tcflag_t c_lflag
- Local modes. This member contains at least the following bits:
- ECHO
- Enable echo.
- ECHOE
- Echo ERASE as destructive backspace.
- ECHOK
- Echo KILL as a line erase.
- ECHONL
- Echo '\n', even if ECHO is off.
- ICANON
- Canonical input mode (line editing enabled).
- IEXTEN
- QNX extensions to POSIX are enabled.
- ISIG
- Enable signals.
- NOFLSH
- Disable flush after interrupt, quit, or suspend.
- TOSTOP
- Send SIGTTOU for background output.
- cc_t c_cc[NCCS]
- Control characters.
The array c_cc includes at least the following control
characters:
- c_cc[VEOF]
- EOF character.
- c_cc[VEOL]
- EOL character.
- c_cc[VERASE]
- ERASE character.
- c_cc[VINTR]
- INTR character.
- c_cc[VKILL]
- KILL character.
- c_cc[VMIN]
- MIN value.
- c_cc[VQUIT]
- QUIT character.
- c_cc[VSUSP]
- SUSP character.
- c_cc[VTIME]
- TIME value.
- c_cc[VSTART]
- START character.
- c_cc[VSTOP]
- STOP character.
The following control characters are also defined, but will only be acted
on if they are immediately preceded by the nonzero characters
in c_cc[VPREFIX][4], and are immediately
followed by
the nonzero characters in c_cc[VSUFFIX][4]
and the IEXTEN bit of c_lflag is set:
- c_cc[VLEFT]
- Left cursor motion.
- c_cc[VRIGHT]
- Right cursor motion.
- c_cc[VUP]
- Up cursor motion.
- c_cc[VDOWN]
- Down cursor motion.
- c_cc[VINS]
- Insert character.
- c_cc[VDEL]
- Delete character.
- c_cc[VRUB]
- Rubout character.
- c_cc[VCAN]
- Cancel character.
- c_cc[VHOME]
- Home character.
- c_cc[VEND]
- End character.
Any of the control characters in the c_cc array can be
disabled by setting that character to the _PC_VDISABLE
parameter which is returned by fpathconf() (typically a zero).
- speed_t c_ispeed
- Input baud rate. This member should be queried and set with the
cfgetispeed() and
cfsetispeed() functions.
- speed_t c_ospeed
- Output baud rate. This member should be queried and set with the
cfgetospeed() and
cfsetospeed() functions.
|
You should use the dev_mode() function in
situations where only the principal terminal modes (ECHO,
ISIG, ICANON and OPOST) are
being affected. |
- 0
- Success
- -1
- An error occurred. errno is set to indicate the error.
- EBADF
- The fildes argument is invalid.
- ENOSYS
- The resource manager associated with fildes doesn't support
this call.
- ENOTTY
- The fildes argument doesn't refer to a terminal device.
See tcsetattr().
POSIX 1003.1
Safety: | |
Interrupt handler |
No |
Signal handler |
Yes |
Thread |
Yes |
dev_mode(),
errno,
fpathconf(),
tcsetattr()
Chapter 7 of POSIX 1003.1