]> rtime.felk.cvut.cz Git - sysless.git/blob - arch/arm/mach-lpc21xx/tools/tolpc/cfsetspeed.c
cmdproc: Make backspace work even in sterm
[sysless.git] / arch / arm / mach-lpc21xx / tools / tolpc / cfsetspeed.c
1 /* Copyright (C) 1992, 1993, 1996, 1997, 1998 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 Library General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    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    Library General Public License for more details.
13
14    You should have received a copy of the GNU Library General Public
15    License along with the GNU C Library; see the file COPYING.LIB.  If not,
16    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17    Boston, MA 02111-1307, USA.  */
18
19 #include <termios.h>
20 #include <errno.h>
21 #include <stddef.h>
22
23 struct speed_struct
24 {
25   speed_t value;
26   speed_t internal;
27 };
28
29 static const struct speed_struct speeds[] =
30   {
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   };
104
105
106 /* Set both the input and output baud rates stored in *TERMIOS_P to SPEED.  */
107 int
108 cfsetspeed (struct termios *termios_p, speed_t speed)
109 {
110   size_t cnt;
111
112   for (cnt = 0; cnt < sizeof (speeds) / sizeof (speeds[0]); ++cnt)
113     if (speed == speeds[cnt].internal)
114       {
115         cfsetispeed (termios_p, speed);
116         cfsetospeed (termios_p, speed);
117         return 0;
118       }
119     else if (speed == speeds[cnt].value)
120       {
121         cfsetispeed (termios_p, speeds[cnt].internal);
122         cfsetospeed (termios_p, speeds[cnt].internal);
123         return 0;
124       }
125
126   __set_errno (EINVAL);
127
128   return -1;
129 }