tcflush() - 端末における入力/出力のフラッシュ

標準

標準/拡張機能 C/C++ 依存項目

POSIX.1
XPG4
XPG4.2
Single UNIX Specification、バージョン 3

両方  

形式

#define _POSIX_SOURCE
#include <termios.h>

int tcflush(int fildes, int where);

機能説明

端末で入力または出力をフラッシュします。
int fildes;
端末装置と関連したファイル記述子を示します。
int where;
termios.h ヘッダー・ファイルに定義されている、次のシンボルのいずれかによって表示された、入力または出力をシステムがフラッシュするかどうかを示します。
シンボル
意味
TCIFLUSH
システムが受け入れたが、アプリケーションが読み取っていない 入力データをフラッシュします。
TCOFLUSH
アプリケーションが書き込んだが、端末に送信されていない 出力データをフラッシュします。
TCIOFLUSH
入出力データの両方をフラッシュします。

tcflush() が、呼び出し元の制御端末に対して バックグラウンド・プロセス・グループから呼び出されると、プロセスが SIGTTOU を処理している方法によっては、SIGTTOU シグナル を生成できます。

SIGTTOU の処理 システムの動作
デフォルトまたはシグナル・ハンドラー SIGTTOU シグナルが生成され、関数は実行されません。 tcflush() は -1 を戻し、errno を EINTR に設定します。
無視またはブロック SIGTTOU シグナルは送信されず、関数は正常に継続します。

戻り値

正常に実行された場合、tcflush() は 0 を戻します。

正常に実行されなかった場合、tcflush() は -1 を戻して、errno を次のいずれかの 値に設定します。
エラー・コード
説明
EBADF
fildes が、有効なオープン・ファイル記述子ではありません。
EINTR
シグナルが tcflush() に割り込みました。
EINVAL
where に、正しくない値があります。
EIO
関数を発行するプロセスのプロセス・グループは孤立した バックグラウンド・プロセス・グループで、関数を発行する プロセスは SIGTTOU を無視またはブロックしていません。
ENOTTY
fildes は、端末と関連していません。

CELEBT05
⁄* CELEBT05

   This example flushes a string.

 *⁄
#define _POSIX_SOURCE
#include <termios.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys⁄stat.h>

main() {
  char Master[]="master.tty";
  char Slave[]="slave.tty";
  char text1[]="string that will be flushed from buffer";
  char text2[]="string that will not be flushed from buffer";
  char data[80];
  int  master, slave;

  if (mknod(Master, S_IFCHR|S_IRUSR|S_IWUSR, 0x00010000 + 10) != 0)
    perror("mknod() error for master tty");
  else {
    if (mknod(Slave, S_IFCHR|S_IRUSR|S_IWUSR, 0x00020000 + 10) != 0)
      perror("mknod() error for slave tty");
    else {
      if ((master = open(Master, O_RDWR|O_NONBLOCK)) < 0)
        perror("open() error for master tty");
      else {
        if ((slave = open(Slave, O_RDWR|O_NONBLOCK)) < 0)
          perror("open() error for slave tty");
        else {
          if (write(slave, text1, strlen(text1)+1) == -1)
            perror("write() error");
          else if (tcflush(slave, TCOFLUSH) != 0)
            perror("tcflush() error");
          else {
            puts("first string is written and tty flushed");
            puts("now writing string that will not be flushed");
            if (write(slave, text2, strlen(text2)+1) == -1)
              perror("write() error");
            else if (read(master, data, sizeof(data)) == -1)
              perror("read() error");
            else printf("read '%s' from the tty¥n", data);
          }
          close(slave);
        }
        close(master);
      }
      unlink(Slave);
    }
    unlink(Master);
  }
}
出力:
first string is written and tty flushed
now writing string that will not be flushed
read 'string that will not be flushed from buffer' from the tty

関連情報