2.9
[glibc/nacl-glibc.git] / termios / cfsetspeed.c
blob436c54bc56bf7340e2b4425379b8b55aa9dc8764
1 /* Copyright (C) 1992,93,96,97,98,2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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. */
19 #include <termios.h>
20 #include <errno.h>
21 #include <stddef.h>
23 struct speed_struct
25 speed_t value;
26 speed_t internal;
29 static const struct speed_struct speeds[] =
31 #ifdef B0
32 { 0, B0 },
33 #endif
34 #ifdef B50
35 { 50, B50 },
36 #endif
37 #ifdef B75
38 { 75, B75 },
39 #endif
40 #ifdef B110
41 { 110, B110 },
42 #endif
43 #ifdef B134
44 { 134, B134 },
45 #endif
46 #ifdef B150
47 { 150, B150 },
48 #endif
49 #ifdef B200
50 { 200, B200 },
51 #endif
52 #ifdef B300
53 { 300, B300 },
54 #endif
55 #ifdef B600
56 { 600, B600 },
57 #endif
58 #ifdef B1200
59 { 1200, B1200 },
60 #endif
61 #ifdef B1200
62 { 1200, B1200 },
63 #endif
64 #ifdef B1800
65 { 1800, B1800 },
66 #endif
67 #ifdef B2400
68 { 2400, B2400 },
69 #endif
70 #ifdef B4800
71 { 4800, B4800 },
72 #endif
73 #ifdef B9600
74 { 9600, B9600 },
75 #endif
76 #ifdef B19200
77 { 19200, B19200 },
78 #endif
79 #ifdef B38400
80 { 38400, B38400 },
81 #endif
82 #ifdef B57600
83 { 57600, B57600 },
84 #endif
85 #ifdef B76800
86 { 76800, B76800 },
87 #endif
88 #ifdef B115200
89 { 115200, B115200 },
90 #endif
91 #ifdef B153600
92 { 153600, B153600 },
93 #endif
94 #ifdef B230400
95 { 230400, B230400 },
96 #endif
97 #ifdef B307200
98 { 307200, B307200 },
99 #endif
100 #ifdef B460800
101 { 460800, B460800 },
102 #endif
103 #ifdef B500000
104 { 500000, B500000 },
105 #endif
106 #ifdef B576000
107 { 576000, B576000 },
108 #endif
109 #ifdef B921600
110 { 921600, B921600 },
111 #endif
112 #ifdef B1000000
113 { 1000000, B1000000 },
114 #endif
115 #ifdef B1152000
116 { 1152000, B1152000 },
117 #endif
118 #ifdef B1500000
119 { 1500000, B1500000 },
120 #endif
121 #ifdef B2000000
122 { 2000000, B2000000 },
123 #endif
124 #ifdef B2500000
125 { 2500000, B2500000 },
126 #endif
127 #ifdef B3000000
128 { 3000000, B3000000 },
129 #endif
130 #ifdef B3500000
131 { 3500000, B3500000 },
132 #endif
133 #ifdef B4000000
134 { 4000000, B4000000 },
135 #endif
139 /* Set both the input and output baud rates stored in *TERMIOS_P to SPEED. */
141 cfsetspeed (struct termios *termios_p, speed_t speed)
143 size_t cnt;
145 for (cnt = 0; cnt < sizeof (speeds) / sizeof (speeds[0]); ++cnt)
146 if (speed == speeds[cnt].internal)
148 cfsetispeed (termios_p, speed);
149 cfsetospeed (termios_p, speed);
150 return 0;
152 else if (speed == speeds[cnt].value)
154 cfsetispeed (termios_p, speeds[cnt].internal);
155 cfsetospeed (termios_p, speeds[cnt].internal);
156 return 0;
159 __set_errno (EINVAL);
161 return -1;