[Previous]
[Contents]
[Next]

dev_mode()

test, and set or clear, input/output modes for a terminal device

Synopsis:

#include <sys/dev.h>
unsigned dev_mode( int fd,
                   unsigned mode,
                   unsigned mask );

Description:

The dev_mode() function is used to test, and optionally set (or clear), one of the input/output modes pertaining to the terminal device associated with fd.

Any mode bits that are set in mask are set to the corresponding bit in mode. The value of the terminal mode before this operation is applied is returned.

At least the following terminal modes are defined in <sys/dev.h>:

_DEV_ECHO
Input is automatically echoed to the device.
_DEV_EDIT
Input line editing is supported. Also known as "cooked" or "canonical" mode. Input characters are not available until a line is "entered" by pressing the Enter key. Line editing characters (like Rubout and Cancel) are supported in this mode, with complete visual feedback.

The absence of this mode is usually known as "raw" mode, and has the effect of disabling line editing keys, and making all keys available to programs as they are received.

_DEV_ISIG
If this bit is set, the INTR (Break) key is interpreted as requesting a SIGINT to be generated, and the START/STOP characters (usually Ctrl -Q and Ctrl -S , respectively) are used for flow control.
_DEV_OSFLOW
START/STOP character processing is supported. This is like _DEV_ISIG without requiring break processing.
_DEV_OPOST
If this bit is set, output processing is performed. This includes the expansion of newlines into CR/LF pairs, as well as any other output processing that may be appropriate for the current terminal.
_DEV_MODES
All of the above (default behavior)

Returns:

The previous terminal mode of the device associated with fd. If an error occurs, -1 is returned and errno is set.

Errors:

ENOSYS
This function is not supported for this fd.
EINVAL
One of the arguments is invalid.

Examples:

#include <sys/dev.h>

int main( void )
  {
    unsigned old_mode;

    /* Examine the current terminal mode */
    old_mode = dev_mode( 0, 0, 0 );

    /* Go completely "raw" by disabling everything */
    dev_mode( 0, 0, _DEV_MODES );

    /* Put terminal in fully edited (default) mode */
    dev_mode( 0, _DEV_MODES, _DEV_MODES );

    /* Turn off echo without affecting other modes */
    dev_mode( 0, 0, _DEV_ECHO );

    /* Turn on output expansions */
    dev_mode( 0, _DEV_OPOST, _DEV_OPOST );

    /* Restore the terminal to its original mode */
    dev_mode( 0, old_mode, _DEV_MODES );
  }

Classification:

QNX

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

See also:

errno, tcgetattr(), tcsetattr()


[Previous]
[Contents]
[Next]