[Previous] [Contents] [Index] [Next]

Caution: This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.

tcsetattr()

Change the terminal control settings for a device

Synopsis:

#include <termios.h>

int tcsetattr( int fildes,
               int optional_actions,
               const struct termios *termios_p );

Arguments:

fildes
The file descriptor associated with the terminal device.
termios_p
A pointer to a termios structure that describes the attributes that you want to set for the terminal device.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The tcsetattr() function sets the current terminal control settings for the opened device indicated by fildes to the values stored in the structure pointed to by termios_p.

The operation of tcsetattr() depends on the values in optional_actions:

TCSANOW
The change is made immediately.
TCSADRAIN
No change is made until all currently written data has been transmitted.
TCSAFLUSH
No change is made until all currently written data has been transmitted, at which point any received but unread data is also discarded.

The termios control structure is defined in <termios.h>. For more information, see tcgetattr().

Returns:

0
Success.
-1
An error occurred; errno is set.

Errors:

EBADF
The argument fildes is invalid;
EINVAL
The argument action is invalid, or one of the members of termios_p is invalid.
ENOSYS
The resource manager associated with fildes doesn't support this call.
ENOTTY
The argument fildes doesn't refer to a terminal device.

Examples:

#include <stdlib.h>
#include <termios.h>

int main( void )
  {
    raw( 0 );
    /*
     * Stdin is now "raw"
     */
    unraw ( 0 );
    return EXIT_SUCCESS;
  }

int raw( fd )
  int fd;
  {
    struct termios termios_p;

    if( tcgetattr( fd, &termios_p ) )
      return( -1 );

    termios_p.c_cc[VMIN]  =  1;
    termios_p.c_cc[VTIME] =  0;
    termios_p.c_lflag &= ~( ECHO|ICANON|ISIG|
              ECHOE|ECHOK|ECHONL );
    termios_p.c_oflag &= ~( OPOST );
    return( tcsetattr( fd, TCSADRAIN, &termios_p ) );
  }

int unraw( fd )
  int fd;
  {
    struct termios termios_p;

    if( tcgetattr( fd, &termios_p ) )
      return( -1 );

    termios_p.c_lflag |= ( ECHO|ICANON|ISIG|
             ECHOE|ECHOK|ECHONL );
    termios_p.c_oflag |= ( OPOST );
    return( tcsetattr( fd, TCSADRAIN, &termios_p ) );
  }

Classification:

POSIX 1003.1

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

errno, select(), tcgetattr(), termios


[Previous] [Contents] [Index] [Next]