Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
#define _POSIX_SOURCE
#include <termios.h>
int tcgetattr(int fildes, struct termios *termptr);
Gets a termios structure, which contains control information for a terminal associated with fildes. It stores that information in a memory location that termptr points to. The contents of a termios structure are described in tcsetattr() — Set the attributes for a terminal.
tcgetattr() can run in either a foreground or background process; however, if the process is in the background, a foreground process may subsequently change the attributes.
tcgetattr() only works in an environment where either a controlling terminal exists, or stdin and stderr refer to tty devices. Specifically, it does not work in a TSO environment.
If successful, tcgetattr() returns 0.
⁄* CELEBT06
This example provides information about the attributes.
*⁄
#define _POSIX_SOURCE
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
main() {
struct termios term;
if (tcgetattr(STDIN_FILENO, &term) != 0)
perror("tcgetatt() error");
else {
if (term.c_iflag & BRKINT)
puts("BRKINT is set");
else
puts("BRKINT is not set");
if (term.c_cflag & PARODD)
puts("Odd parity is used");
else
puts("Even parity is used");
if (term.c_lflag & ECHO)
puts("ECHO is set");
else
puts("ECHO is not set");
printf("The end-of-file character is x'%02x'\n",
term.c_cc[VEOF]);
}
}
ECHO is set
The End Of File character is x'37'