
#include <termios.h> int tcgetattr(int fileDescriptor, struct termios *terminal);
tcgetattr stores the attributes of a terminal device in
a termios structure. The fields of termios
(declared in <termios.h>) are flags that identify
terminal modes and control characters. The following arguments
are passed to tcgetattr:
fileDescriptor
terminal
termios structure. The tcgetattr
function fills this structure with the attributes of the terminal
referred to by fileDescriptor.
tcgetattr from either a foreground or
background process. However, if called from a background process,
terminal attributes may be changed by a subsequent call from a
foreground process.
tcgetattr returns a 0 if successful and a -1 if unsuccessful.
tcgetattr to
determine the terminal attributes for stdout:
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#define NOTATTY 1
main()
{
int ttyDevice = STDOUT_FILENO;
struct termios termAttributes;
/* Make sure file descriptor is for a TTY device. */
if ( ! isatty(ttyDevice) )
return(NOTATTY);
/* Get terminal attributes and then determine if terminal */
/* start and stop is enabled and if terminal is in */
/* canonical mode. */
else {
if (tcgetattr(ttyDevice, &termAttributes) != 0)
perror("tcgetattr error");
else {
if (termAttributes.c_iflag & IXON)
printf("Terminal start and stop is enabled.n");
if (termAttributes.c_lflag & ICANON)
printf("Terminal is in canonical mode.n");
}
}
return(EXIT_SUCCESS);
}
cfgetispeed, cfgetospeed, tcsetattr
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.