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


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


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>:

Input is automatically echoed to the device.
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.

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.
START/STOP character processing is supported. This is like _DEV_ISIG without requiring break processing.
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.
All of the above (default behavior)


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


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


#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 );



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

See also:

errno, tcgetattr(), tcsetattr()