cfgetispeed() - 入力ボー・レートの判別

標準

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

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

両方  

形式

#define _POSIX_SOURCE
#include <termios.h>

speed_t cfgetispeed(const struct termios *termptr);

機能説明

*termptr が示す termios 構造体から 入力ボー・レートを取り出します。termios 構造体には、端末に関する情報が 入っています。プログラムでは、最初に tcgetattr() を使用 して termios 構造体を取得し、次に cfgetispeed() を使用して その構造体から速度を取り出すようにしてください。そうすると、プログラムは、cfgetispeed() を使用してその構造体に 新しいボー・レートを設定し、tcsetattr() を使用して変更値をシステムに 渡すことができます。

z/OS®UNIX アプリケーションでは、cfsetispeed() を使用して有効な 速度を設定し、tcsetattr() を使用してその速度をシステムに渡すことが できますが、その速度は疑似端末の命令に影響しません。しかし、命令が OCS リモート端末に対して発行された場合は、その命令 に影響があります。

戻り値

cfgetispeed() は、ボー・レートを示すコードを戻します。表 1 を参照してください。これらのコードは、termios.h ヘッダー・ファイルに定義されていて、符号なし整数型です。

文書化される errno 値はありません。

表 1. ボー・レート・コード
B0 ハングアップ
B50 50 ボー
B75 75 ボー
B110 110 ボー
B134 134.5 ボー
B150 150 ボー
B200 200 ボー
B300 300 ボー
B600 600 ボー
B1200 1200 ボー
B1800 1800 ボー
B2400 2400 ボー
B4800 4800 ボー
B9600 9600 ボー
B19200 19,200 ボー
B38400 38,400 ボー

CELEBC05
⁄* CELEBC05

   This example determines the speed of stdin.

 *⁄
#define _POSIX_SOURCE
#include <termios.h>
#include <stdio.h>

char *see_speed(speed_t speed) {
  static char   SPEED[20];
  switch (speed) {
    case B0:       strcpy(SPEED, "B0");
                   break;
    case B50:      strcpy(SPEED, "B50");
                   break;
    case B75:      strcpy(SPEED, "B75");
                   break;
    case B110:     strcpy(SPEED, "B110");
                   break;
    case B134:     strcpy(SPEED, "B134");
                   break;
    case B150:     strcpy(SPEED, "B150");
                   break;
    case B200:     strcpy(SPEED, "B200");
                   break;
    case B300:     strcpy(SPEED, "B300");
                   break;
    case B600:     strcpy(SPEED, "B600");
                   break;
    case B1200:    strcpy(SPEED, "B1200");
                   break;
    case B1800:    strcpy(SPEED, "B1800");
                   break;
    case B2400:    strcpy(SPEED, "B2400");
                   break;
    case B4800:    strcpy(SPEED, "B4800");
                   break;
    case B9600:    strcpy(SPEED, "B9600");
                   break;
    case B19200:   strcpy(SPEED, "B19200");
                   break;
    case B38400:   strcpy(SPEED, "B38400");
                   break;
    default:       sprintf(SPEED, "unknown (%d)", (int) speed);
  }
  return SPEED;
}

main() {
  struct termios term;
  speed_t speed;

  if (tcgetattr(0, &term) != 0)
    perror("tcgetattr() error");
  else {
    speed = cfgetispeed(&term);
    printf("cfgetispeed() says the speed of stdin is %s¥n",
           see_speed(speed));
  }
}
出力:
cfgetispeed() says the speed of stdin is B0

関連情報