Patch by Vasilis Kaoutsis:

* Check against maximum baud rate in cfset{i,o}speed().
* Changed some functions comments to doxygen style.
* Sorted speed macros in termios.h.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24647 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2008-03-29 12:52:10 +00:00
parent 6287376408
commit 29674ea8cb
2 changed files with 28 additions and 19 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2004-2005, Haiku Inc. All Rights Reserved.
* Copyright 2004-2008, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _TERMIOS_H_
@ -106,11 +106,11 @@ struct termios {
#define B4800 0x0C
#define B9600 0x0D
#define B19200 0x0E
#define B38400 0x0F
#define B57600 0x10
#define B115200 0x11
#define B230400 0x12
#define B31250 0x13 /* for MIDI */
#define B31250 0x0F /* for MIDI */
#define B38400 0x10
#define B57600 0x11
#define B115200 0x12
#define B230400 0x13
#define CSIZE 0x20 /* character size */
#define CS5 0x00 /* only 7 and 8 bits supported */

View File

@ -11,8 +11,7 @@
#include <errno.h>
/** get the attributes of the TTY device at fd */
/*! get the attributes of the TTY device at fd */
int
tcgetattr(int fd, struct termios *termios)
{
@ -20,8 +19,7 @@ tcgetattr(int fd, struct termios *termios)
}
/** set the attributes for the TTY device at fd */
/*! set the attributes for the TTY device at fd */
int
tcsetattr(int fd, int opt, const struct termios *termios)
{
@ -50,8 +48,7 @@ tcsetattr(int fd, int opt, const struct termios *termios)
}
/** wait for all output to be transmitted */
/*! wait for all output to be transmitted */
int
tcdrain(int fd)
{
@ -65,8 +62,7 @@ tcdrain(int fd)
}
/** suspend or restart transmission */
/*! suspend or restart transmission */
int
tcflow(int fd, int action)
{
@ -86,8 +82,7 @@ tcflow(int fd, int action)
}
/** flush all pending data (input or output) */
/*! flush all pending data (input or output) */
int
tcflush(int fd, int queueSelector)
{
@ -95,8 +90,7 @@ tcflush(int fd, int queueSelector)
}
/** send zero bits for the specified duration */
/*! send zero bits for the specified duration */
int
tcsendbreak(int fd, int duration)
{
@ -116,6 +110,16 @@ cfgetispeed(const struct termios *termios)
int
cfsetispeed(struct termios *termios, speed_t speed)
{
/* Check for values that the system cannot handle:
greater values than B230400 which is
the maximum value defined in termios.h
Note that errors from hardware device are detected only
until the tcsetattr() function is called */
if (speed > B230400) {
errno = EINVAL;
return -1;
}
termios->c_ispeed = speed;
return 0;
}
@ -131,7 +135,12 @@ cfgetospeed(const struct termios *termios)
int
cfsetospeed(struct termios *termios, speed_t speed)
{
/* Check for unaccepted speed values (see above) */
if (speed > B230400) {
errno = EINVAL;
return -1;
}
termios->c_ospeed = speed;
return 0;
}