tcdrain()

Updated: April 19, 2023

Wait until all output has been transmitted to a device

Synopsis:

#include <termios.h>

int tcdrain( int filedes );

Arguments:

filedes
A file descriptor that's associated with the device that you want to wait for.

Library:

libc

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

Description:

The tcdrain() function waits until all output has been physically transmitted to the device associated with filedes, or until a signal is received.

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

EBADF
The argument filedes is invalid.
EINTR
A signal interrupted the operation.
ENOSYS
The resource manager associated with filedes doesn't support this call.
ENOTTY
The argument filedes doesn't refer to a terminal device.

Examples:

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

int main( void )
  {
    int filedes;

    filedes = open( "/dev/ser1", O_RDWR );
    write( filedes, "ATH", 3 );

    /* Wait for data to transmit before returning */
    tcdrain( filedes );
    close( filedes );
    return EXIT_SUCCESS;
  }

Classification:

POSIX 1003.1

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