]> sourceware.org Git - glibc.git/blame - sysdeps/unix/bsd/sun/sunos4/speed.c
Update.
[glibc.git] / sysdeps / unix / bsd / sun / sunos4 / speed.c
CommitLineData
28f540f4 1/* `struct termios' speed frobnication functions. SunOS 4 version.
478b92f0
UD
2 Copyright (C) 1991, 1992, 1993, 1996, 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
28f540f4 4
478b92f0
UD
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.
28f540f4 9
478b92f0
UD
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.
28f540f4 14
478b92f0
UD
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 not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
28f540f4 19
28f540f4
RM
20#include <stddef.h>
21#include <errno.h>
22#include <termios.h>
23
c4029823 24static const speed_t speeds[] =
28f540f4
RM
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 };
43
44
45/* Return the output baud rate stored in *TERMIOS_P. */
46speed_t
c4029823
UD
47cfgetospeed (termios_p)
48 const struct termios *termios_p;
28f540f4
RM
49{
50 return termios_p->c_cflag & CBAUD;
51}
52
53/* Return the input baud rate stored in *TERMIOS_P. */
54speed_t
c4029823
UD
55cfgetispeed (termios_p)
56 const struct termios *termios_p;
28f540f4
RM
57{
58 return (termios_p->c_cflag & CIBAUD) >> IBSHIFT;
59}
60
61/* Set the output baud rate stored in *TERMIOS_P to SPEED. */
62int
c4029823
UD
63cfsetospeed (termios_p, speed)
64 struct termios *termios_p;
65 speed_t speed;
28f540f4
RM
66{
67 register unsigned int i;
68
69 if (termios_p == NULL)
70 {
c4029823 71 __set_errno (EINVAL);
28f540f4
RM
72 return -1;
73 }
74
75 /* This allows either B1200 or 1200 to work. XXX
76 Do we really want to try to support this, given that
77 fetching the speed must return one or the other? */
78
79 for (i = 0; i < sizeof (speeds) / sizeof (speeds[0]); ++i)
80 if (i == speed || speeds[i] == speed)
81 {
82 termios_p->c_cflag &= ~CBAUD;
83 termios_p->c_cflag |= i;
84 return 0;
85 }
86
c4029823 87 __set_errno (EINVAL);
28f540f4
RM
88 return -1;
89}
90
91/* Set the input baud rate stored in *TERMIOS_P to SPEED. */
92int
c4029823
UD
93cfsetispeed (termios_p, speed)
94 struct termios *termios_p;
95 speed_t speed;
28f540f4
RM
96{
97 register unsigned int i;
98
99 if (termios_p == NULL)
100 {
c4029823 101 __set_errno (EINVAL);
28f540f4
RM
102 return -1;
103 }
104
105 /* See comment in cfsetospeed (above). */
106 for (i = 0; i < sizeof (speeds) / sizeof (speeds[0]); ++i)
107 if (i == speed || speeds[i] == speed)
108 {
109 termios_p->c_cflag &= ~CIBAUD;
110 termios_p->c_cflag |= i << IBSHIFT;
111 return 0;
112 }
113
c4029823 114 __set_errno (EINVAL);
28f540f4
RM
115 return -1;
116}
This page took 0.079239 seconds and 5 git commands to generate.