cfsetispeed -- Set Input Baud Rate

SYNOPSIS

 #include <termios.h>


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

DESCRIPTION

cfsetispeed is used to set a new input baud rate in the termios structure pointed to by terminal. This structure is defined in <termios.h> and contains terminal attribute information.

The tcgetattr function must be used to obtain a copy of the termios structure before you can use the cfsetispeed function to set the input baud rate. The cfsetispeed function changes the baud rate in this copy and the tcsetattr functions can then be used to update the termios control structure.

The defined type, speed_t, specifies the baud rate. Each value is associated with an asynchronous line speed as follows:


 
Return Value Baud Rate
B0 hang up B50 50 baud B75 75 baud B110 110 baud B134 134.5 baud B150 150 baud B200 200 baud B300 300 baud B600 600 baud B1200 1200 baud B1800 1800 baud B2400 2400 baud B4800 4800 baud B9600 9600 baud B19200 19,200 baud B38400 38,400 baud

RETURN VALUE

If successful, cfsetispeed returns 0. A -1 is returned if unsuccessful.

PORTABILITY

The cfsetispeed function is defined by the POSIX.1 standard and provides portability between operating environments. Note that OpenEdition only supports pseudoterminals and that baud rate does not affect the operation of a pseudoterminal.

EXAMPLE

The following example illustrates the use of cfsetispeed to set a new output baud rate:
  #include <sys/types.h>
  #include <termios.h>
  #include <unistd.h>

  main()
  {
     struct termios termAttr;
     speed_t baudRate;

        /* Make a copy of the termios structure. */
     tcgetattr(STDIN_FILENO, &termAttr);
        /* Get the input speed.                  */
     baudRate = cfgetispeed(&termAttr);
        /* Set output speed if not 9600 baud.    */
     if (baudRate != B9600) {
        cfsetispeed(&termAttr, B9600);
        tcsetattr(STDIN_FILENO, TCSANOW, &termAttr);
     }
  }

 

RELATED FUNCTIONS

cfgetispeed, cfsetospeed, tcsetattr