]> git.ipfire.org Git - thirdparty/glibc.git/blame - termios/cfsetspeed.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / termios / cfsetspeed.c
CommitLineData
04277e02 1/* Copyright (C) 1992-2019 Free Software Foundation, Inc.
df4ef2ab 2 This file is part of the GNU C Library.
28f540f4 3
df4ef2ab 4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
28f540f4 8
df4ef2ab
UD
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
41bdb6e2 12 Lesser General Public License for more details.
28f540f4 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6 15 License along with the GNU C Library; if not, see
5a82c748 16 <https://www.gnu.org/licenses/>. */
28f540f4 17
28f540f4
RM
18#include <termios.h>
19#include <errno.h>
20#include <stddef.h>
21
8c0c3e6d 22struct speed_struct
d41c6f61
UD
23{
24 speed_t value;
25 speed_t internal;
8c0c3e6d
UD
26};
27
28static const struct speed_struct speeds[] =
d41c6f61
UD
29 {
30#ifdef B0
31 { 0, B0 },
32#endif
33#ifdef B50
34 { 50, B50 },
35#endif
36#ifdef B75
37 { 75, B75 },
38#endif
39#ifdef B110
40 { 110, B110 },
41#endif
42#ifdef B134
43 { 134, B134 },
44#endif
45#ifdef B150
46 { 150, B150 },
47#endif
48#ifdef B200
49 { 200, B200 },
50#endif
51#ifdef B300
52 { 300, B300 },
53#endif
54#ifdef B600
55 { 600, B600 },
56#endif
57#ifdef B1200
58 { 1200, B1200 },
59#endif
60#ifdef B1200
61 { 1200, B1200 },
62#endif
63#ifdef B1800
64 { 1800, B1800 },
65#endif
66#ifdef B2400
67 { 2400, B2400 },
68#endif
69#ifdef B4800
70 { 4800, B4800 },
71#endif
72#ifdef B9600
73 { 9600, B9600 },
74#endif
75#ifdef B19200
76 { 19200, B19200 },
77#endif
78#ifdef B38400
79 { 38400, B38400 },
80#endif
81#ifdef B57600
82 { 57600, B57600 },
83#endif
84#ifdef B76800
85 { 76800, B76800 },
86#endif
87#ifdef B115200
88 { 115200, B115200 },
89#endif
90#ifdef B153600
91 { 153600, B153600 },
92#endif
93#ifdef B230400
94 { 230400, B230400 },
95#endif
96#ifdef B307200
97 { 307200, B307200 },
98#endif
99#ifdef B460800
100 { 460800, B460800 },
15c64502
RM
101#endif
102#ifdef B500000
103 { 500000, B500000 },
104#endif
105#ifdef B576000
106 { 576000, B576000 },
107#endif
108#ifdef B921600
109 { 921600, B921600 },
110#endif
111#ifdef B1000000
112 { 1000000, B1000000 },
113#endif
114#ifdef B1152000
115 { 1152000, B1152000 },
116#endif
117#ifdef B1500000
118 { 1500000, B1500000 },
119#endif
120#ifdef B2000000
121 { 2000000, B2000000 },
122#endif
123#ifdef B2500000
124 { 2500000, B2500000 },
125#endif
126#ifdef B3000000
127 { 3000000, B3000000 },
128#endif
129#ifdef B3500000
130 { 3500000, B3500000 },
131#endif
132#ifdef B4000000
133 { 4000000, B4000000 },
d41c6f61
UD
134#endif
135 };
136
137
28f540f4 138/* Set both the input and output baud rates stored in *TERMIOS_P to SPEED. */
26b4d766 139int
d41c6f61 140cfsetspeed (struct termios *termios_p, speed_t speed)
28f540f4 141{
d41c6f61
UD
142 size_t cnt;
143
55c14926
UD
144 for (cnt = 0; cnt < sizeof (speeds) / sizeof (speeds[0]); ++cnt)
145 if (speed == speeds[cnt].internal)
d41c6f61
UD
146 {
147 cfsetispeed (termios_p, speed);
148 cfsetospeed (termios_p, speed);
26b4d766 149 return 0;
d41c6f61 150 }
55c14926
UD
151 else if (speed == speeds[cnt].value)
152 {
153 cfsetispeed (termios_p, speeds[cnt].internal);
154 cfsetospeed (termios_p, speeds[cnt].internal);
26b4d766 155 return 0;
55c14926 156 }
d41c6f61
UD
157
158 __set_errno (EINVAL);
26b4d766
UD
159
160 return -1;
28f540f4 161}