OSDN Git Service

Replace FSF snail mail address with URLs
[uclinux-h8/uClibc.git] / libc / termios / cfsetspeed.c
1 /* Copyright (C) 1992,93,96,97,98,2001 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <http://www.gnu.org/licenses/>.  */
17
18 #include <termios.h>
19 #include <errno.h>
20 #include <stddef.h>
21
22 #ifdef __USE_BSD
23
24
25 struct speed_struct
26 {
27   speed_t value;
28   speed_t internal;
29 };
30
31 static const struct speed_struct speeds[] =
32   {
33 #ifdef B0
34     { 0, B0 },
35 #endif
36 #ifdef B50
37     { 50, B50 },
38 #endif
39 #ifdef B75
40     { 75, B75 },
41 #endif
42 #ifdef B110
43     { 110, B110 },
44 #endif
45 #ifdef B134
46     { 134, B134 },
47 #endif
48 #ifdef B150
49     { 150, B150 },
50 #endif
51 #ifdef B200
52     { 200, B200 },
53 #endif
54 #ifdef B300
55     { 300, B300 },
56 #endif
57 #ifdef B600
58     { 600, B600 },
59 #endif
60 #ifdef B1200
61     { 1200, B1200 },
62 #endif
63 #ifdef B1200
64     { 1200, B1200 },
65 #endif
66 #ifdef B1800
67     { 1800, B1800 },
68 #endif
69 #ifdef B2400
70     { 2400, B2400 },
71 #endif
72 #ifdef B4800
73     { 4800, B4800 },
74 #endif
75 #ifdef B9600
76     { 9600, B9600 },
77 #endif
78 #ifdef B19200
79     { 19200, B19200 },
80 #endif
81 #ifdef B38400
82     { 38400, B38400 },
83 #endif
84 #ifdef B57600
85     { 57600, B57600 },
86 #endif
87 #ifdef B76800
88     { 76800, B76800 },
89 #endif
90 #ifdef B115200
91     { 115200, B115200 },
92 #endif
93 #ifdef B153600
94     { 153600, B153600 },
95 #endif
96 #ifdef B230400
97     { 230400, B230400 },
98 #endif
99 #ifdef B307200
100     { 307200, B307200 },
101 #endif
102 #ifdef B460800
103     { 460800, B460800 },
104 #endif
105 #ifdef B500000
106     { 500000, B500000 },
107 #endif
108 #ifdef B576000
109     { 576000, B576000 },
110 #endif
111 #ifdef B614400
112     { 614400, B614400 },
113 #endif
114 #ifdef B921600
115     { 921600, B921600 },
116 #endif
117 #ifdef B1000000
118     { 1000000, B1000000 },
119 #endif
120 #ifdef B1152000
121     { 1152000, B1152000 },
122 #endif
123 #ifdef B1500000
124     { 1500000, B1500000 },
125 #endif
126 #ifdef B1843200
127     { 1843200, B1843200 },
128 #endif
129 #ifdef B2000000
130     { 2000000, B2000000 },
131 #endif
132 #ifdef B2500000
133     { 2500000, B2500000 },
134 #endif
135 #ifdef B3000000
136     { 3000000, B3000000 },
137 #endif
138 #ifdef B3500000
139     { 3500000, B3500000 },
140 #endif
141 #ifdef B4000000
142     { 4000000, B4000000 },
143 #endif
144 #ifdef B6250000
145     { 6250000, B6250000 },
146 #endif
147 #ifdef B12500000
148     { 12500000, B12500000 },
149 #endif
150   };
151
152
153 /* Set both the input and output baud rates stored in *TERMIOS_P to SPEED.  */
154 int cfsetspeed (struct termios *termios_p, speed_t speed)
155 {
156   size_t cnt;
157
158   for (cnt = 0; cnt < sizeof (speeds) / sizeof (speeds[0]); ++cnt)
159     if (speed == speeds[cnt].internal)
160       {
161         cfsetispeed (termios_p, speed);
162         cfsetospeed (termios_p, speed);
163         return 0;
164       }
165     else if (speed == speeds[cnt].value)
166       {
167         cfsetispeed (termios_p, speeds[cnt].internal);
168         cfsetospeed (termios_p, speeds[cnt].internal);
169         return 0;
170       }
171
172   __set_errno (EINVAL);
173
174   return -1;
175 }
176 #endif