1 /* `struct termios' speed frobnication functions. SunOS 4 version.
2 Copyright (C) 1991,1992,1993,1996,1997,2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 static const speed_t speeds
[] =
45 /* Return the output baud rate stored in *TERMIOS_P. */
47 cfgetospeed (termios_p
)
48 const struct termios
*termios_p
;
50 return termios_p
->c_cflag
& CBAUD
;
53 /* Return the input baud rate stored in *TERMIOS_P. */
55 cfgetispeed (termios_p
)
56 const struct termios
*termios_p
;
58 return (termios_p
->c_cflag
& CIBAUD
) >> IBSHIFT
;
61 /* Set the output baud rate stored in *TERMIOS_P to SPEED. */
63 cfsetospeed (termios_p
, speed
)
64 struct termios
*termios_p
;
67 register unsigned int i
;
69 if (termios_p
== NULL
)
75 /* This allows either B1200 or 1200 to work. XXX
76 Do we really want to try to support this, given that
77 fetching the speed must return one or the other? */
79 for (i
= 0; i
< sizeof (speeds
) / sizeof (speeds
[0]); ++i
)
80 if (i
== speed
|| speeds
[i
] == speed
)
82 termios_p
->c_cflag
&= ~CBAUD
;
83 termios_p
->c_cflag
|= i
;
90 libc_hidden_def (cfsetospeed
)
92 /* Set the input baud rate stored in *TERMIOS_P to SPEED. */
94 cfsetispeed (termios_p
, speed
)
95 struct termios
*termios_p
;
98 register unsigned int i
;
100 if (termios_p
== NULL
)
102 __set_errno (EINVAL
);
106 /* See comment in cfsetospeed (above). */
107 for (i
= 0; i
< sizeof (speeds
) / sizeof (speeds
[0]); ++i
)
108 if (i
== speed
|| speeds
[i
] == speed
)
110 termios_p
->c_cflag
&= ~CIBAUD
;
111 termios_p
->c_cflag
|= i
<< IBSHIFT
;
115 __set_errno (EINVAL
);
118 libc_hidden_def (cfsetispeed
)