![]() Chapter Contents |
![]() Previous |
![]() Next |
| tcgetattr |
| Portability: | POSIX.1 conforming |
| SYNOPSIS | |
| DESCRIPTION | |
| RETURN VALUE | |
| EXAMPLE | |
| RELATED FUNCTIONS |
| SYNOPSIS |
#include <termios.h> int tcgetattr(int fileDescriptor, struct termios *terminal);
| DESCRIPTION |
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
.
You can call
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.
| RETURN VALUE |
tcgetattr
returns a
0
if successful and a
-1
if unsuccessful.
| EXAMPLE |
The following example illustrates the
use of
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);
}
| RELATED FUNCTIONS |
cfgetispeed
,
cfgetospeed
,
tcsetattr
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.