]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/speed.c
Document new files for Linux i386/ELF port.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / speed.c
CommitLineData
d2f5be2a
UD
1/* `struct termios' speed frobnication functions. Linux version.
2Copyright (C) 1991, 1992, 1993, 1995 Free Software Foundation, Inc.
3This file is part of the GNU C Library.
4
5The GNU C Library is free software; you can redistribute it and/or
6modify it under the terms of the GNU Library General Public License as
7published by the Free Software Foundation; either version 2 of the
8License, or (at your option) any later version.
9
10The GNU C Library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13Library General Public License for more details.
14
15You should have received a copy of the GNU Library General Public
16License along with the GNU C Library; see the file COPYING.LIB. If
17not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18Cambridge, MA 02139, USA. */
19
20#include <stddef.h>
21#include <errno.h>
22#include <termios.h>
23
24static const speed_t speeds[] =
25 {
26 0,
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 38400, /* Mention this twice here is a trick. */
43 57600,
44 115200,
45 230400,
46 };
47
48
49/* Return the output baud rate stored in *TERMIOS_P. */
50speed_t
51cfgetospeed (termios_p)
52 const struct termios *termios_p;
53{
54 speed_t retval = termios_p->c_cflag & (CBAUD | CBAUDEX);
55
56 if (retval & CBAUDEX)
57 {
58 retval &= ~CBAUDEX;
59 retval |= CBAUD + 1;
60 }
61
62 return retval;
63}
64
65/* Return the input baud rate stored in *TERMIOS_P.
66 For Linux there is no difference between input and output speed. */
67strong_alias (cfgetospeed, cfgetispeed);
68
69/* Set the output baud rate stored in *TERMIOS_P to SPEED. */
70int
71cfsetospeed (termios_p, speed)
72 struct termios *termios_p;
73 speed_t speed;
74{
75 register unsigned int i;
76
77 if (termios_p == NULL)
78 {
79 errno = EINVAL;
80 return -1;
81 }
82
83 /* This allows either B1200 or 1200 to work. XXX
84 Do we really want to try to support this, given that
85 fetching the speed must return one or the other? */
86
87 for (i = 0; i < sizeof (speeds) / sizeof (speeds[0]); ++i)
88 if (i == speed || speeds[i] == speed)
89 {
90 termios_p->c_cflag &= ~(CBAUD | CBAUDEX);
91 termios_p->c_cflag |= (i & CBAUD);
92 if (i & ~CBAUD)
93 termios_p->c_cflag |= CBAUDEX;
94 return 0;
95 }
96
97 errno = EINVAL;
98 return -1;
99}
100
101/* Set the input baud rate stored in *TERMIOS_P to SPEED.
102 For Linux there is no difference between input and output speed. */
103strong_alias (cfsetospeed, cfsetispeed);