cfgetospeed -- Determine Output Baud Rate

SYNOPSIS

 #include <termios.h>

 speed_t cfgetospeed(const struct termios *termptr);
 

DESCRIPTION

cfgetospeed returns the output baud rate, which is stored in the termios structure pointed to by termptr. 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 cfgetospeed function to extract the output baud rate from the copy of the structure. The cfsetospeed and tcsetattr functions can then be used to change the output baud rate.

RETURN VALUE

The return value is a defined type, speed_t, which is located in <termios.h>. 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

PORTABILITY

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

EXAMPLE

The following code fragment illustrates the use of tcgetattr and cfgetospeed to determine the speed of stdout.
  #include <sys/types.h>
  #include <termios.h>
  #include <unistd.h>
  #include <stdio.h
                      >
  main()
  {
     struct termios termAttr;
     speed_t baudRate;
     char *outputSpeed = "unknown";

        /* Obtain a copy of the termios structure for stdout. */
     tcgetattr(STDOUT_FILENO, &termAttr);
        /* Get the output speed.                              */
     baudRate = cfgetospeed(&termAttr);
        /* Print output speed.                                */
     switch (baudRate) {
        case B0:      outputSpeed = "none"; break;
        case B50:     outputSpeed = "50 baud"; break;
        case B110:    outputSpeed = "110 baud"; break;
        case B134:    outputSpeed = "134 baud"; break;
        case B150:    outputSpeed = "150 baud"; break;
        case B200:    outputSpeed = "200 baud"; break;
        case B300:    outputSpeed = "300 baud"; break;
        case B600:    outputSpeed = "600 baud"; break;
        case B1200:   outputSpeed = "1200 baud"; break;
        case B1800:   outputSpeed = "1800 baud"; break;
        case B2400:   outputSpeed = "2400 baud"; break;
        case B4800:   outputSpeed = "4800 baud"; break;
        case B9600:   outputSpeed = "9600 baud"; break;
        case B19200:  outputSpeed = "19200 baud"; break;
        case B38400:  outputSpeed = "38400 baud"; break;
     }
     printf("Output speed = %sn", outputSpeed);
  }

 

RELATED FUNCTIONS

cfgetispeed, cfsetospeed, tcgetattr