cfsetispeed() — Set the input baud rate in the termios

Standards

Standards / Extensions C or C++ Dependencies

POSIX.1
XPG4
XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _POSIX_SOURCE
#include <termios.h>

int cfsetispeed(struct termios *termptr, speed_t speed);

General description

Specifies a new input baud rate for the termios control structure, *termptr. cfsetispeed() records this new baud rate in the control structure but does not actually change the terminal device file. The program must call tcsetattr() to modify the terminal device file to reflect the settings in the termios structure.

A program should first use tcgetattr() to get the termios structure. Then it should use cfsetispeed() to set the speed in termios and tcsetattr() to pass the modified termios structure to the system.

Although in a z/OS® UNIX application valid speeds can be set with cfsetispeed() and passed to the system with tcsetattr(), the speed has no effect on the operation of a pseudoterminal. However, the operation will have an effect if issued for an OCS remote terminal.

The speed argument indicates the new baud rate with one of the following codes, defined in the termios.h header file. The codes have an unsigned integer type. Table 1 shows the codes to set the baud rate.

Returned value

If successful, cfsetispeed() sets the baud rate in the control structure and returns 0.

If unsuccessful, cfsetispeed() returns -1 and sets errno to one of the following values:
Error Code
Description
EINVAL
An unsupported value for speed

Example

CELEBC07
⁄* CELEBC07

   This example specifies a new input baud rate.

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

main() {
  struct termios term;

  if (tcgetattr(0, &term) != 0)
    perror("tcgetattr() error");
  else if (cfsetispeed(&term, B0) != 0)
    perror("cfsetispeed() error");
  else if (tcsetattr(0, TCSANOW, &term) != 0)
    perror("tcsetattr() error");
}

Related information