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:
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _TERMIOS_H_
|
#ifndef _TERMIOS_H_
|
||||||
@@ -106,11 +106,11 @@ struct termios {
|
|||||||
#define B4800 0x0C
|
#define B4800 0x0C
|
||||||
#define B9600 0x0D
|
#define B9600 0x0D
|
||||||
#define B19200 0x0E
|
#define B19200 0x0E
|
||||||
#define B38400 0x0F
|
#define B31250 0x0F /* for MIDI */
|
||||||
#define B57600 0x10
|
#define B38400 0x10
|
||||||
#define B115200 0x11
|
#define B57600 0x11
|
||||||
#define B230400 0x12
|
#define B115200 0x12
|
||||||
#define B31250 0x13 /* for MIDI */
|
#define B230400 0x13
|
||||||
|
|
||||||
#define CSIZE 0x20 /* character size */
|
#define CSIZE 0x20 /* character size */
|
||||||
#define CS5 0x00 /* only 7 and 8 bits supported */
|
#define CS5 0x00 /* only 7 and 8 bits supported */
|
||||||
|
|||||||
@@ -11,8 +11,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
|
||||||
/** get the attributes of the TTY device at fd */
|
/*! get the attributes of the TTY device at fd */
|
||||||
|
|
||||||
int
|
int
|
||||||
tcgetattr(int fd, struct termios *termios)
|
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
|
int
|
||||||
tcsetattr(int fd, int opt, const struct termios *termios)
|
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
|
int
|
||||||
tcdrain(int fd)
|
tcdrain(int fd)
|
||||||
{
|
{
|
||||||
@@ -65,8 +62,7 @@ tcdrain(int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** suspend or restart transmission */
|
/*! suspend or restart transmission */
|
||||||
|
|
||||||
int
|
int
|
||||||
tcflow(int fd, int action)
|
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
|
int
|
||||||
tcflush(int fd, int queueSelector)
|
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
|
int
|
||||||
tcsendbreak(int fd, int duration)
|
tcsendbreak(int fd, int duration)
|
||||||
{
|
{
|
||||||
@@ -116,6 +110,16 @@ cfgetispeed(const struct termios *termios)
|
|||||||
int
|
int
|
||||||
cfsetispeed(struct termios *termios, speed_t speed)
|
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;
|
termios->c_ispeed = speed;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -131,7 +135,12 @@ cfgetospeed(const struct termios *termios)
|
|||||||
int
|
int
|
||||||
cfsetospeed(struct termios *termios, speed_t speed)
|
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;
|
termios->c_ospeed = speed;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user