From 4e5f73581c4e2587434dfccc281d504f4c4dfe56 Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Wed, 2 Aug 1995 12:03:12 +0000 Subject: [PATCH] Better approximation for TIOCGETP (gtty) for non-standard speeds. Old variant returns 38400 for them, now it returns nearest matched rounded down, expect speeds in range 0 > speed < 50 rounded up to not produce hangup. --- sys/kern/tty_compat.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/sys/kern/tty_compat.c b/sys/kern/tty_compat.c index 26ed1ec380f..b266b56859d 100644 --- a/sys/kern/tty_compat.c +++ b/sys/kern/tty_compat.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)tty_compat.c 8.1 (Berkeley) 6/10/93 - * $Id: tty_compat.c,v 1.14 1995/08/01 23:27:36 ache Exp $ + * $Id: tty_compat.c,v 1.15 1995/08/02 06:55:35 ache Exp $ */ /* @@ -80,9 +80,22 @@ static struct speedtab compatspeeds[] = { }; static int compatspcodes[] = { 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, - 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, + 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200 }; +static +int ttcompatspeedtab(speed, table) + int speed; + register struct speedtab *table; +{ + if (speed == 0) + return (0); /* hangup */ + for ( ; table->sp_speed > 0; table++) + if (table->sp_speed <= speed) /* nearest one, rounded down */ + return (table->sp_code); + return (1); /* 50, min and not hangup */ +} + int ttsetcompat(tp, com, data, term) register struct tty *tp; int *com; @@ -187,16 +200,12 @@ ttcompat(tp, com, data, flag) case TIOCGETP: { register struct sgttyb *sg = (struct sgttyb *)data; register cc_t *cc = tp->t_cc; - register speed; - speed = ttspeedtab(tp->t_ospeed, compatspeeds); - sg->sg_ospeed = (speed == -1) ? MAX_SPEED : speed; + sg->sg_ospeed = ttcompatspeedtab(tp->t_ospeed, compatspeeds); if (tp->t_ispeed == 0) sg->sg_ispeed = sg->sg_ospeed; - else { - speed = ttspeedtab(tp->t_ispeed, compatspeeds); - sg->sg_ispeed = (speed == -1) ? MAX_SPEED : speed; - } + else + sg->sg_ispeed = ttcompatspeedtab(tp->t_ispeed, compatspeeds); sg->sg_erase = cc[VERASE]; sg->sg_kill = cc[VKILL]; sg->sg_flags = tp->t_flags = ttcompatgetflags(tp);