tcflush -- Flush Terminal Input or Output

SYNOPSIS

 #include <termios.h>

 int tcflush(int fileDescriptor, int queue);
 

DESCRIPTION

tcflush is called by a process to flush all input that has received but not yet been read by a terminal, or all output written but not transmitted to the terminal. Flushed data are discarded and cannot be retrieved.
fileDescriptor
is a file discriptor that refers to a terminal device.
queue
is a symbolic constant that specifies which queue to flush. The values for queue are defined in <termios.h> and can be any of the following:
TCIFLUSH
flushes the input queue, which contains data that have been received but not yet read.
TCOFLUSH
flushes the output queue, which contains data that have been written but not yet transmitted.
TCIOFLUSH
flushes both the input and output queue.

RETURN VALUE

tcflush returns a 0 if successful and a -1 if unsuccessful. If tcflush is called from a background process with a file descriptor that refers to the controlling terminal for the process, a SIGTTOU signal may be generated. This will cause the function call to be unsuccessful, returning a -1 and setting errno to EINTR. If SIGTTOU is blocked, the function call proceeds normally.

EXAMPLE

The following example illustrates the use of tcflush to flush both the input and output queues of a terminal:
  #include <sys/types.h&gt>
  #include <termios.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <stdlib.h>

  main()
  {
     int ttyDevice = STDOUT_FILENO;

        /* Make sure file descriptor is for a TTY device.   */
     if ( ! isatty(ttyDevice) ) {
        printf("Not a TTY device.n");
        return(EXIT_FAILURE);
     }

        /* Flush both the input and output queues.          */
     else {
        if (tcflush(ttyDevice, TCIOFLUSH) == 0)
           printf("The input and output queues have been flushed.n");
        else
           perror("tcflush error");
     }
     return(EXIT_SUCCESS);
  }

 

RELATED FUNCTIONS

tcdrain, tcflow


Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.