]>
Commit | Line | Data |
---|---|---|
d2f5be2a | 1 | /* `struct termios' speed frobnication functions. Linux version. |
613a76ff | 2 | Copyright (C) 1991, 1992, 1993, 1995, 1996 Free Software Foundation, Inc. |
d2f5be2a UD |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Library General Public License as | |
7 | published by the Free Software Foundation; either version 2 of the | |
8 | License, or (at your option) any later version. | |
9 | ||
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 | Library General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Library General Public | |
16 | License along with the GNU C Library; see the file COPYING.LIB. If | |
17 | not, write to the Free Software Foundation, Inc., 675 Mass Ave, | |
18 | Cambridge, MA 02139, USA. */ | |
19 | ||
20 | #include <stddef.h> | |
21 | #include <errno.h> | |
22 | #include <termios.h> | |
23 | ||
24 | static const speed_t speeds[] = | |
25 | { | |
26 | 0, | |
27 | 50, | |
28 | 75, | |
29 | 110, | |
30 | 134, | |
31 | 150, | |
32 | 200, | |
33 | 300, | |
34 | 600, | |
35 | 1200, | |
36 | 1800, | |
37 | 2400, | |
38 | 4800, | |
39 | 9600, | |
40 | 19200, | |
41 | 38400, | |
84724245 | 42 | #ifndef __alpha__ |
d2f5be2a | 43 | 38400, /* Mention this twice here is a trick. */ |
84724245 | 44 | #endif |
d2f5be2a UD |
45 | 57600, |
46 | 115200, | |
47 | 230400, | |
613a76ff | 48 | 460800, |
d2f5be2a UD |
49 | }; |
50 | ||
51 | ||
52 | /* Return the output baud rate stored in *TERMIOS_P. */ | |
53 | speed_t | |
54 | cfgetospeed (termios_p) | |
55 | const struct termios *termios_p; | |
56 | { | |
57 | speed_t retval = termios_p->c_cflag & (CBAUD | CBAUDEX); | |
58 | ||
59 | if (retval & CBAUDEX) | |
60 | { | |
61 | retval &= ~CBAUDEX; | |
62 | retval |= CBAUD + 1; | |
63 | } | |
64 | ||
65 | return retval; | |
66 | } | |
67 | ||
68 | /* Return the input baud rate stored in *TERMIOS_P. | |
69 | For Linux there is no difference between input and output speed. */ | |
70 | strong_alias (cfgetospeed, cfgetispeed); | |
71 | ||
72 | /* Set the output baud rate stored in *TERMIOS_P to SPEED. */ | |
73 | int | |
613a76ff | 74 | cfsetospeed (termios_p, speed) |
d2f5be2a UD |
75 | struct termios *termios_p; |
76 | speed_t speed; | |
77 | { | |
78 | register unsigned int i; | |
79 | ||
80 | if (termios_p == NULL) | |
81 | { | |
c4029823 | 82 | __set_errno (EINVAL); |
d2f5be2a UD |
83 | return -1; |
84 | } | |
85 | ||
86 | /* This allows either B1200 or 1200 to work. XXX | |
87 | Do we really want to try to support this, given that | |
88 | fetching the speed must return one or the other? */ | |
89 | ||
90 | for (i = 0; i < sizeof (speeds) / sizeof (speeds[0]); ++i) | |
91 | if (i == speed || speeds[i] == speed) | |
92 | { | |
93 | termios_p->c_cflag &= ~(CBAUD | CBAUDEX); | |
94 | termios_p->c_cflag |= (i & CBAUD); | |
95 | if (i & ~CBAUD) | |
96 | termios_p->c_cflag |= CBAUDEX; | |
97 | return 0; | |
98 | } | |
99 | ||
c4029823 | 100 | __set_errno (EINVAL); |
d2f5be2a UD |
101 | return -1; |
102 | } | |
103 | ||
104 | /* Set the input baud rate stored in *TERMIOS_P to SPEED. | |
105 | For Linux there is no difference between input and output speed. */ | |
106 | strong_alias (cfsetospeed, cfsetispeed); |