xref: /titanic_52/usr/src/lib/libxcurses2/src/libc/xcurses/baudrate.c (revision 88447a05f537aabe9a1bc3d5313f22581ec992a7)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1995-1998 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /* LINTLIBRARY */
30 
31 /*
32  * baudrate.c
33  *
34  * XCurses Library
35  *
36  * Copyright 1990, 1995 by Mortice Kern Systems Inc.  All rights reserved.
37  *
38  */
39 
40 #ifdef M_RCSID
41 #ifndef lint
42 static char rcsID[] =
43 "$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
44 "libxcurses/src/libc/xcurses/rcs/baudrate.c 1.3 1998/06/04 19:55:42 "
45 "cbates Exp $";
46 #endif
47 #endif
48 
49 #include <private.h>
50 
51 typedef struct {
52 	speed_t	speed;
53 	int	value;
54 } t_baud;
55 
56 static const t_baud speeds[] = {
57 	{ B0, 0 },
58 	{ B50, 50 },
59 	{ B75, 75 },
60 	{ B110, 110 },
61 	{ B134, 134 },
62 	{ B150, 150 },
63 	{ B200, 200 },
64 	{ B300, 300 },
65 	{ B600, 600 },
66 	{ B1200, 1200 },
67 	{ B1800, 1800 },
68 	{ B2400, 2400 },
69 	{ B4800, 4800 },
70 	{ B9600, 9600 },
71 	{ B19200, 19200 },
72 	{ B38400, 38400 },
73 	{ (speed_t) -1, -1 }
74 };
75 
76 /*
77  * Return the output speed of the terminal.  The number returned is in
78  * bits per second and is an integer.
79  */
80 int
81 baudrate(void)
82 {
83 	int	i;
84 	speed_t	value;
85 
86 	value = cfgetospeed(PTERMIOS(_prog));
87 
88 	for (i = 0; speeds[i].speed != (speed_t) -1; ++i)
89 		if (speeds[i].speed == value)
90 			break;
91 
92 	return (speeds[i].value);
93 }
94