Tue Jul 9 09:37:55 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[glibc.git] / sysdeps / unix / sysv / linux / speed.c
blob0ad48a23d8460ed3289199f166a4e752f7f1fba3
1 /* `struct termios' speed frobnication functions. Linux version.
2 Copyright (C) 1991, 1992, 1993, 1995, 1996 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
20 #include <stddef.h>
21 #include <errno.h>
22 #include <termios.h>
24 static const speed_t speeds[] =
27 50,
28 75,
29 110,
30 134,
31 150,
32 200,
33 300,
34 600,
35 1200,
36 1800,
37 2400,
38 4800,
39 9600,
40 19200,
41 38400,
42 #ifndef __alpha__
43 38400, /* Mention this twice here is a trick. */
44 #endif
45 57600,
46 115200,
47 230400,
48 460800,
52 /* Return the output baud rate stored in *TERMIOS_P. */
53 speed_t
54 cfgetospeed (termios_p)
55 const struct termios *termios_p;
57 speed_t retval = termios_p->c_cflag & (CBAUD | CBAUDEX);
59 if (retval & CBAUDEX)
61 retval &= ~CBAUDEX;
62 retval |= CBAUD + 1;
65 return retval;
68 /* Return the input baud rate stored in *TERMIOS_P.
69 For Linux there is no difference between input and output speed. */
70 strong_alias (cfgetospeed, cfgetispeed);
72 /* Set the output baud rate stored in *TERMIOS_P to SPEED. */
73 int
74 cfsetospeed (termios_p, speed)
75 struct termios *termios_p;
76 speed_t speed;
78 register unsigned int i;
80 if (termios_p == NULL)
82 errno = EINVAL;
83 return -1;
86 /* This allows either B1200 or 1200 to work. XXX
87 Do we really want to try to support this, given that
88 fetching the speed must return one or the other? */
90 for (i = 0; i < sizeof (speeds) / sizeof (speeds[0]); ++i)
91 if (i == speed || speeds[i] == speed)
93 termios_p->c_cflag &= ~(CBAUD | CBAUDEX);
94 termios_p->c_cflag |= (i & CBAUD);
95 if (i & ~CBAUD)
96 termios_p->c_cflag |= CBAUDEX;
97 return 0;
100 errno = EINVAL;
101 return -1;
104 /* Set the input baud rate stored in *TERMIOS_P to SPEED.
105 For Linux there is no difference between input and output speed. */
106 strong_alias (cfsetospeed, cfsetispeed);