Chapter Contents |
Previous |
Next |
cfgetospeed |
Portability: | POSIX.1 conforming |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
PORTABILITY | |
EXAMPLE | |
RELATED FUNCTIONS |
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:
PORTABILITY |
The
cfgetospeed
function is defined by the POSIX.1 standard and provides
portablility between operating environments. Note that USS 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 = %s\n", outputSpeed); }
RELATED FUNCTIONS |
cfgetispeed
,
cfsetospeed
,
tcgetattr
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.