cfsetspeed()

QNX SDP8.0C Library ReferenceAPIDeveloper

Set the input and output baud rates in a termios structure

Synopsis:

#include <termios.h>

int cfsetspeed( struct termios* termios_p,
                 speed_t speed );

Arguments:

termios_p
A pointer to a termios structure that describes the terminal's control attributes.
speed
The new value for both the input speed and the output speed. There are predefined values in the form B followed by the baud rate in decimal format (e.g., B9600 for 9600). Using these values is convenient and helps catch syntax errors, but you can pass in any uint32_t value.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The cfsetspeed() function sets the input and the output baud rate (speed) within the termios structure pointed to by termios_p to be speed. This function provides a convenient way of setting both rates in a single call as opposed to issuing separate calls to cfsetispeed() and cfsetospeed(), which can lead to different results depending on the relative order in which you call these other functions.

You can get a valid termios control structure for an opened device by calling tcgetattr().

Note:
  • The new baud rates aren't effective until you call tcsetattr() with this modified termios structure.
  • Attempts to set baud rates to values that aren't supported by the hardware are ignored, and cause tcsetattr() to return an error, but cfsetspeed() doesn't indicate an error.

Returns:

In this release, this function always returns 0 (success).

Examples:

#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

int main( void )
  {
    int fd;
    struct termios termios_p;
    speed_t speed;

    fd = open( "/dev/ser1", O_RDWR );
    tcgetattr( fd, &termios_p );

    /*
     * Set input and output baud rates to same value
     */
    speed = 9600;
    cfsetspeed( &termios_p, speed );
    tcsetattr( fd, TCSADRAIN, &termios_p );

    close( fd );
    return EXIT_SUCCESS;
  }

Classification:

POSIX 1003.1

Safety:
Cancellation pointNo
Signal handlerYes
ThreadYes
Page updated: