blob: b1d54cb9f73bf2c853bb9a3c169f6c9e9802975d [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* 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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
18
19#include <termios.h>
20#include <errno.h>
21#include <stddef.h>
22
23#ifdef __USE_BSD
24
25
26struct speed_struct
27{
28 speed_t value;
29 speed_t internal;
30};
31
32static const struct speed_struct speeds[] =
33 {
34#ifdef B0
35 { 0, B0 },
36#endif
37#ifdef B50
38 { 50, B50 },
39#endif
40#ifdef B75
41 { 75, B75 },
42#endif
43#ifdef B110
44 { 110, B110 },
45#endif
46#ifdef B134
47 { 134, B134 },
48#endif
49#ifdef B150
50 { 150, B150 },
51#endif
52#ifdef B200
53 { 200, B200 },
54#endif
55#ifdef B300
56 { 300, B300 },
57#endif
58#ifdef B600
59 { 600, B600 },
60#endif
61#ifdef B1200
62 { 1200, B1200 },
63#endif
64#ifdef B1200
65 { 1200, B1200 },
66#endif
67#ifdef B1800
68 { 1800, B1800 },
69#endif
70#ifdef B2400
71 { 2400, B2400 },
72#endif
73#ifdef B4800
74 { 4800, B4800 },
75#endif
76#ifdef B9600
77 { 9600, B9600 },
78#endif
79#ifdef B19200
80 { 19200, B19200 },
81#endif
82#ifdef B38400
83 { 38400, B38400 },
84#endif
85#ifdef B57600
86 { 57600, B57600 },
87#endif
88#ifdef B76800
89 { 76800, B76800 },
90#endif
91#ifdef B115200
92 { 115200, B115200 },
93#endif
94#ifdef B153600
95 { 153600, B153600 },
96#endif
97#ifdef B230400
98 { 230400, B230400 },
99#endif
100#ifdef B307200
101 { 307200, B307200 },
102#endif
103#ifdef B460800
104 { 460800, B460800 },
105#endif
106#ifdef B500000
107 { 500000, B500000 },
108#endif
109#ifdef B576000
110 { 576000, B576000 },
111#endif
112#ifdef B614400
113 { 614400, B614400 },
114#endif
115#ifdef B921600
116 { 921600, B921600 },
117#endif
118#ifdef B1000000
119 { 1000000, B1000000 },
120#endif
121#ifdef B1152000
122 { 1152000, B1152000 },
123#endif
124#ifdef B1500000
125 { 1500000, B1500000 },
126#endif
127#ifdef B1843200
128 { 1843200, B1843200 },
129#endif
130#ifdef B2000000
131 { 2000000, B2000000 },
132#endif
133#ifdef B2500000
134 { 2500000, B2500000 },
135#endif
136#ifdef B3000000
137 { 3000000, B3000000 },
138#endif
139#ifdef B3500000
140 { 3500000, B3500000 },
141#endif
142#ifdef B4000000
143 { 4000000, B4000000 },
144#endif
145#ifdef B6250000
146 { 6250000, B6250000 },
147#endif
148#ifdef B12500000
149 { 12500000, B12500000 },
150#endif
151 };
152
153
154/* Set both the input and output baud rates stored in *TERMIOS_P to SPEED. */
155int cfsetspeed (struct termios *termios_p, speed_t speed)
156{
157 size_t cnt;
158
159 for (cnt = 0; cnt < sizeof (speeds) / sizeof (speeds[0]); ++cnt)
160 if (speed == speeds[cnt].internal)
161 {
162 cfsetispeed (termios_p, speed);
163 cfsetospeed (termios_p, speed);
164 return 0;
165 }
166 else if (speed == speeds[cnt].value)
167 {
168 cfsetispeed (termios_p, speeds[cnt].internal);
169 cfsetospeed (termios_p, speeds[cnt].internal);
170 return 0;
171 }
172
173 __set_errno (EINVAL);
174
175 return -1;
176}
177#endif