(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / unix / bsd / sun / sunos4 / speed.c
blob262d70fdfb81502a1c4c35ebe08ea3016ee2882a
1 /* `struct termios' speed frobnication functions. SunOS 4 version.
2 Copyright (C) 1991,1992,1993,1996,1997,2002 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 Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 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,
45 /* Return the output baud rate stored in *TERMIOS_P. */
46 speed_t
47 cfgetospeed (termios_p)
48 const struct termios *termios_p;
50 return termios_p->c_cflag & CBAUD;
53 /* Return the input baud rate stored in *TERMIOS_P. */
54 speed_t
55 cfgetispeed (termios_p)
56 const struct termios *termios_p;
58 return (termios_p->c_cflag & CIBAUD) >> IBSHIFT;
61 /* Set the output baud rate stored in *TERMIOS_P to SPEED. */
62 int
63 cfsetospeed (termios_p, speed)
64 struct termios *termios_p;
65 speed_t speed;
67 register unsigned int i;
69 if (termios_p == NULL)
71 __set_errno (EINVAL);
72 return -1;
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? */
79 for (i = 0; i < sizeof (speeds) / sizeof (speeds[0]); ++i)
80 if (i == speed || speeds[i] == speed)
82 termios_p->c_cflag &= ~CBAUD;
83 termios_p->c_cflag |= i;
84 return 0;
87 __set_errno (EINVAL);
88 return -1;
90 libc_hidden_def (cfsetospeed)
92 /* Set the input baud rate stored in *TERMIOS_P to SPEED. */
93 int
94 cfsetispeed (termios_p, speed)
95 struct termios *termios_p;
96 speed_t speed;
98 register unsigned int i;
100 if (termios_p == NULL)
102 __set_errno (EINVAL);
103 return -1;
106 /* See comment in cfsetospeed (above). */
107 for (i = 0; i < sizeof (speeds) / sizeof (speeds[0]); ++i)
108 if (i == speed || speeds[i] == speed)
110 termios_p->c_cflag &= ~CIBAUD;
111 termios_p->c_cflag |= i << IBSHIFT;
112 return 0;
115 __set_errno (EINVAL);
116 return -1;
118 libc_hidden_def (cfsetispeed)