Chapter Contents

Previous

Next
tcflush

tcflush



Flush Terminal Input or Output

Portability: POSIX.1 conforming


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS


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


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.