2 * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Copyright 2003, Daniel Reinhold, danielre@users.sf.net. All rights reserved.
5 * Distributed under the terms of the MIT License.
13 #include <errno_private.h>
16 /*! get the attributes of the TTY device at fd */
18 tcgetattr(int fd
, struct termios
*termios
)
20 return ioctl(fd
, TCGETA
, termios
);
24 /*! set the attributes for the TTY device at fd */
26 tcsetattr(int fd
, int opt
, const struct termios
*termios
)
32 // set the attributes immediately
36 // wait for ouput to finish before setting the attributes
44 // no other valid options
49 return ioctl(fd
, method
, termios
);
53 /*! wait for all output to be transmitted */
57 /* Some termios implementations have a TIOCDRAIN command
58 * expressly for this purpose (e.g. ioctl(fd, TIOCDRAIN, 0).
59 * However, the BeOS implementation adheres to another
60 * interface which uses a non-zero last parameter to the
61 * TCSBRK ioctl to signify this functionality.
63 return ioctl(fd
, TCSBRK
, 1);
67 /*! suspend or restart transmission */
69 tcflow(int fd
, int action
)
83 return ioctl(fd
, TCXONC
, action
);
87 /*! flush all pending data (input or output) */
89 tcflush(int fd
, int queueSelector
)
91 return ioctl(fd
, TCFLSH
, queueSelector
);
95 /*! send zero bits for the specified duration */
97 tcsendbreak(int fd
, int duration
)
99 // Posix spec says this should take ~ 0.25 to 0.5 seconds.
100 // As the interpretation of the duration is undefined, we'll just ignore it
101 return ioctl(fd
, TCSBRK
, 0);
106 cfgetispeed(const struct termios
*termios
)
108 if ((termios
->c_cflag
& CBAUD
) == CBAUD
)
109 return termios
->c_ispeed
;
111 return termios
->c_cflag
& CBAUD
;
116 cfsetispeed(struct termios
*termios
, speed_t speed
)
118 /* Check for custom baudrates, which must be stored in the c_ispeed
119 field instead of inlined in the flags.
120 Note that errors from hardware device (unsupported baudrates, etc) are
121 detected only when the tcsetattr() function is called */
122 if (speed
> B31250
) {
123 termios
->c_cflag
|= CBAUD
;
124 termios
->c_ispeed
= speed
;
128 termios
->c_cflag
&= ~CBAUD
;
129 termios
->c_cflag
|= speed
;
135 cfgetospeed(const struct termios
*termios
)
137 if ((termios
->c_cflag
& CBAUD
) == CBAUD
)
138 return termios
->c_ospeed
;
140 return termios
->c_cflag
& CBAUD
;
145 cfsetospeed(struct termios
*termios
, speed_t speed
)
147 /* Check for custom speed values (see above) */
148 if (speed
> B31250
) {
149 termios
->c_cflag
|= CBAUD
;
150 termios
->c_ospeed
= speed
;
154 termios
->c_cflag
&= ~CBAUD
;
155 termios
->c_cflag
|= speed
;
161 cfmakeraw(struct termios
*termios
)
163 termios
->c_iflag
&= ~(IGNBRK
| BRKINT
| PARMRK
| ISTRIP
| INLCR
| IGNCR
165 termios
->c_oflag
&= ~OPOST
;
166 termios
->c_lflag
&= ~(ECHO
| ECHONL
| ICANON
| ISIG
| IEXTEN
);
167 termios
->c_cflag
&= ~(CSIZE
| PARENB
);
168 termios
->c_cflag
|= CS8
;