Chapter Contents |
Previous |
Next |
cfgetispeed |
Portability: | POSIX.1 conforming |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
PORTABILITY | |
EXAMPLE | |
RELATED FUNCTIONS |
SYNOPSIS |
#include <termios.h> speed_t cfgetispeed(const struct termios *termptr);
DESCRIPTION |
cfgetispeed
returns the input 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
cfgetispeed
function to extract
the input baud rate from the copy of the structure. The
cfsetispeed
and
tcsetattr
functions can then be used to change the input 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
cfgetispeed
function is defined by the POSIX.1 standard and provides
portability between operating environments. Note that UNIX System
Services (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
stdin
.
#include <sys/types.h> #include <termios.h> #include <unistd.h> #include <stdio.h> main() { struct termios termAttr; speed_t baudRate; char *inputSpeed = "unknown"; /* Obtain a copy of the termios structure for stdin. */ tcgetattr(STDIN_FILENO, &termAttr); /* Get the input speed. */ baudRate = cfgetispeed(&termAttr); /* Print input speed. */ switch (baudRate) { case B0: inputSpeed = "none"; break; case B50: inputSpeed = "50 baud"; break; case B110: inputSpeed = "110 baud"; break; case B134: inputSpeed = "134 baud"; break; case B150: inputSpeed = "150 baud"; break; case B200: inputSpeed = "200 baud"; break; case B300: inputSpeed = "300 baud"; break; case B600: inputSpeed = "600 baud"; break; case B1200: inputSpeed = "1200 baud"; break; case B1800: inputSpeed = "1800 baud"; break; case B2400: inputSpeed = "2400 baud"; break; case B4800: inputSpeed = "4800 baud"; break; case B9600: inputSpeed = "9600 baud"; break; case B19200: inputSpeed = "19200 baud"; break; case B38400: inputSpeed = "38400 baud"; break; } printf("Input speed = %s\n", inputSpeed); }
RELATED FUNCTIONS |
cfgetospeed
,
cfsetispeed
,
tcgetattr
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.