2 /***************************************************************************
4 ****************************************************************************
5 * ncurses is copyright (C) 1992-1995 *
7 * zmbenhal@netcom.com *
9 * esr@snark.thyrsus.com *
11 * Permission is hereby granted to reproduce and distribute ncurses *
12 * by any means and for any fee, whether alone or as part of a *
13 * larger distribution, in source or in binary form, PROVIDED *
14 * this notice is included with any such distribution, and is not *
15 * removed from any of its header files. Mention of ncurses in any *
16 * applications linked with it is highly appreciated. *
18 * ncurses comes AS IS with no warranty, implied or expressed. *
20 ***************************************************************************/
28 #include <curses.priv.h>
29 #include <term.h> /* cur_term, pad_char */
31 MODULE_ID("$Id: lib_baudrate.c,v 1.7 1997/04/26 17:41:48 tom Exp $")
37 * Returns the current terminal's baud rate.
46 static struct speed const speeds[] = {
61 #define MAX_BAUD B9600
64 #define MAX_BAUD B19200
74 #define MAX_BAUD B38400
84 #define MAX_BAUD B57600
89 #define MAX_BAUD B115200
103 T((T_CALLED("baudrate()")));
106 * In debugging, allow the environment symbol to override when we're
107 * redirecting to a file, so we can construct repeatable test-cases
108 * that take into account costs that depend on baudrate.
111 if (!isatty(fileno(SP->_ofp))
112 && (debug_rate = getenv("BAUDRATE")) != 0) {
113 if (sscanf(debug_rate, "%d", &ret) != 1)
121 ret = cfgetospeed(&cur_term->Nttyb);
123 ret = cur_term->Nttyb.sg_ospeed;
125 if(ret < 0 || ret > MAX_BAUD)
128 for (i = 0; i < (sizeof(speeds) / sizeof(struct speed)); i++)
129 if (speeds[i].s == (speed_t)ret)
131 SP->_baudrate = speeds[i].sp;
134 returnCode(SP->_baudrate);