fenv: only allow to enable for supported architectures
[uclibc-ng.git] / libc / termios / speed.c
bloba32e5ed716a281480b9d906cc4dd2b30e85e7e53
1 /* `struct termios' speed frobnication functions. Linux version.
2 Copyright (C) 1991,1992,1993,1995,1996,1997,1998,2000,2002,2003
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <stddef.h>
21 #include <errno.h>
22 #include <termios.h>
25 /* This is a gross hack around a kernel bug. If the cfsetispeed functions
26 is called with the SPEED argument set to zero this means use the same
27 speed as for output. But we don't have independent input and output
28 speeds and therefore cannot record this.
30 We use an unused bit in the `c_iflag' field to keep track of this
31 use of `cfsetispeed'. The value here must correspond to the one used
32 in `tcsetattr.c'. */
33 #define IBAUD0 020000000000
36 /* Return the output baud rate stored in *TERMIOS_P. */
37 speed_t cfgetospeed (const struct termios *termios_p)
39 return termios_p->c_cflag & (CBAUD | CBAUDEX);
42 /* Return the input baud rate stored in *TERMIOS_P.
43 Although for Linux there is no difference between input and output
44 speed, the numerical 0 is a special case for the input baud rate. It
45 should set the input baud rate to the output baud rate. */
46 speed_t cfgetispeed (const struct termios *termios_p)
48 return ((termios_p->c_iflag & IBAUD0)
49 ? 0 : termios_p->c_cflag & (CBAUD | CBAUDEX));
52 /* Set the output baud rate stored in *TERMIOS_P to SPEED. */
53 int cfsetospeed (struct termios *termios_p, speed_t speed)
55 if ((speed & ~CBAUD) != 0
56 && (speed < B57600 || speed > __MAX_BAUD))
58 __set_errno (EINVAL);
59 return -1;
62 termios_p->c_cflag &= ~(CBAUD | CBAUDEX);
63 termios_p->c_cflag |= speed;
65 return 0;
67 libc_hidden_def (cfsetospeed)
70 /* Set the input baud rate stored in *TERMIOS_P to SPEED.
71 Although for Linux there is no difference between input and output
72 speed, the numerical 0 is a special case for the input baud rate. It
73 should set the input baud rate to the output baud rate. */
74 int cfsetispeed (struct termios *termios_p, speed_t speed)
76 if ((speed & ~CBAUD) != 0
77 && (speed < B57600 || speed > __MAX_BAUD))
79 __set_errno (EINVAL);
80 return -1;
83 if (speed == 0)
84 termios_p->c_iflag |= IBAUD0;
85 else
87 termios_p->c_iflag &= ~IBAUD0;
88 termios_p->c_cflag &= ~(CBAUD | CBAUDEX);
89 termios_p->c_cflag |= speed;
92 return 0;
94 libc_hidden_def (cfsetispeed)