]>
Commit | Line | Data |
---|---|---|
d2f5be2a UD |
1 | /* `struct termios' speed frobnication functions. Linux version. |
2 | Copyright (C) 1991, 1992, 1993, 1995 Free Software Foundation, Inc. | |
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, | |
42 | 38400, /* Mention this twice here is a trick. */ | |
43 | 57600, | |
44 | 115200, | |
45 | 230400, | |
46 | }; | |
47 | ||
48 | ||
49 | /* Return the output baud rate stored in *TERMIOS_P. */ | |
50 | speed_t | |
51 | cfgetospeed (termios_p) | |
52 | const struct termios *termios_p; | |
53 | { | |
54 | speed_t retval = termios_p->c_cflag & (CBAUD | CBAUDEX); | |
55 | ||
56 | if (retval & CBAUDEX) | |
57 | { | |
58 | retval &= ~CBAUDEX; | |
59 | retval |= CBAUD + 1; | |
60 | } | |
61 | ||
62 | return retval; | |
63 | } | |
64 | ||
65 | /* Return the input baud rate stored in *TERMIOS_P. | |
66 | For Linux there is no difference between input and output speed. */ | |
67 | strong_alias (cfgetospeed, cfgetispeed); | |
68 | ||
69 | /* Set the output baud rate stored in *TERMIOS_P to SPEED. */ | |
70 | int | |
71 | cfsetospeed (termios_p, speed) | |
72 | struct termios *termios_p; | |
73 | speed_t speed; | |
74 | { | |
75 | register unsigned int i; | |
76 | ||
77 | if (termios_p == NULL) | |
78 | { | |
79 | errno = EINVAL; | |
80 | return -1; | |
81 | } | |
82 | ||
83 | /* This allows either B1200 or 1200 to work. XXX | |
84 | Do we really want to try to support this, given that | |
85 | fetching the speed must return one or the other? */ | |
86 | ||
87 | for (i = 0; i < sizeof (speeds) / sizeof (speeds[0]); ++i) | |
88 | if (i == speed || speeds[i] == speed) | |
89 | { | |
90 | termios_p->c_cflag &= ~(CBAUD | CBAUDEX); | |
91 | termios_p->c_cflag |= (i & CBAUD); | |
92 | if (i & ~CBAUD) | |
93 | termios_p->c_cflag |= CBAUDEX; | |
94 | return 0; | |
95 | } | |
96 | ||
97 | errno = EINVAL; | |
98 | return -1; | |
99 | } | |
100 | ||
101 | /* Set the input baud rate stored in *TERMIOS_P to SPEED. | |
102 | For Linux there is no difference between input and output speed. */ | |
103 | strong_alias (cfsetospeed, cfsetispeed); |