Move calls to __restore_termios() into the failing path of the functions

that fail - instead of in most of the callers.
All rather pointless if tcsetattr() fails to set the mode we want we
are very unlikely to be able to restore any later on.
This commit is contained in:
dsl 2009-11-01 22:11:27 +00:00
parent 57843c1579
commit 905b39a994
3 changed files with 36 additions and 39 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: get_wch.c,v 1.6 2008/04/14 20:33:59 jdc Exp $ */
/* $NetBSD: get_wch.c,v 1.7 2009/11/01 22:11:27 dsl Exp $ */
/*
* Copyright (c) 2005 The NetBSD Foundation Inc.
@ -36,7 +36,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: get_wch.c,v 1.6 2008/04/14 20:33:59 jdc Exp $");
__RCSID("$NetBSD: get_wch.c,v 1.7 2009/11/01 22:11:27 dsl Exp $");
#endif /* not lint */
#include <string.h>
@ -557,10 +557,8 @@ wget_wch(WINDOW *win, wint_t *ch)
win->flags & __NOTIMEOUT ? 0 : 1, 0);
break;
case 0:
if (__nodelay() == ERR) {
__restore_termios();
if (__nodelay() == ERR)
return ERR;
}
ret = inkey(&inp, 0, 0);
break;
default:
@ -576,16 +574,12 @@ wget_wch(WINDOW *win, wint_t *ch)
case -1:
break;
case 0:
if (__nodelay() == ERR) {
__restore_termios();
if (__nodelay() == ERR)
return ERR;
}
break;
default:
if (__timeout(win->delay) == ERR) {
__restore_termios();
if (__timeout(win->delay) == ERR)
return ERR;
}
break;
}
@ -616,10 +610,8 @@ wget_wch(WINDOW *win, wint_t *ch)
__CTRACE(__CTRACE_INPUT, "wget_wch got '%s'\n", unctrl(inp));
#endif
if (win->delay > -1) {
if (__delay() == ERR) {
__restore_termios();
if (__delay() == ERR)
return ERR;
}
}
__restore_termios();

View File

@ -1,4 +1,4 @@
/* $NetBSD: getch.c,v 1.52 2009/02/09 12:45:59 jdc Exp $ */
/* $NetBSD: getch.c,v 1.53 2009/11/01 22:11:27 dsl Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)getch.c 8.2 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: getch.c,v 1.52 2009/02/09 12:45:59 jdc Exp $");
__RCSID("$NetBSD: getch.c,v 1.53 2009/11/01 22:11:27 dsl Exp $");
#endif
#endif /* not lint */
@ -844,10 +844,8 @@ wgetch(WINDOW *win)
inp = inkey (win->flags & __NOTIMEOUT ? 0 : 1, 0);
break;
case 0:
if (__nodelay() == ERR) {
__restore_termios();
if (__nodelay() == ERR)
return ERR;
}
inp = inkey(0, 0);
break;
default:
@ -858,22 +856,16 @@ wgetch(WINDOW *win)
switch (win->delay)
{
case -1:
if (__delay() == ERR) {
__restore_termios();
if (__delay() == ERR)
return ERR;
}
break;
case 0:
if (__nodelay() == ERR) {
__restore_termios();
if (__nodelay() == ERR)
return ERR;
}
break;
default:
if (__timeout(win->delay) == ERR) {
__restore_termios();
if (__timeout(win->delay) == ERR)
return ERR;
}
break;
}
@ -902,10 +894,8 @@ wgetch(WINDOW *win)
__CTRACE(__CTRACE_INPUT, "wgetch got '%s'\n", unctrl(inp));
#endif
if (win->delay > -1) {
if (__delay() == ERR) {
__restore_termios();
if (__delay() == ERR)
return ERR;
}
}
__restore_termios();

View File

@ -1,4 +1,4 @@
/* $NetBSD: tty.c,v 1.40 2007/05/28 15:01:58 blymn Exp $ */
/* $NetBSD: tty.c,v 1.41 2009/11/01 22:11:27 dsl Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)tty.c 8.6 (Berkeley) 1/10/95";
#else
__RCSID("$NetBSD: tty.c,v 1.40 2007/05/28 15:01:58 blymn Exp $");
__RCSID("$NetBSD: tty.c,v 1.41 2009/11/01 22:11:27 dsl Exp $");
#endif
#endif /* not lint */
@ -302,8 +302,13 @@ __delay(void)
_cursesi_screen->baset.c_cc[VMIN] = 1;
_cursesi_screen->baset.c_cc[VTIME] = 0;
return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
TCSASOFT : TCSANOW, _cursesi_screen->curt) ? ERR : OK);
if (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
TCSASOFT : TCSANOW, _cursesi_screen->curt)) {
__restore_termios();
return ERR;
}
return OK;
}
int
@ -325,8 +330,13 @@ __nodelay(void)
_cursesi_screen->baset.c_cc[VMIN] = 0;
_cursesi_screen->baset.c_cc[VTIME] = 0;
return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
TCSASOFT : TCSANOW, _cursesi_screen->curt) ? ERR : OK);
if (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
TCSASOFT : TCSANOW, _cursesi_screen->curt)) {
__restore_termios();
return ERR;
}
return OK;
}
void
@ -380,9 +390,14 @@ __timeout(int delay)
_cursesi_screen->baset.c_cc[VMIN] = 0;
_cursesi_screen->baset.c_cc[VTIME] = delay;
return (tcsetattr(fileno(_cursesi_screen->infd),
if (tcsetattr(fileno(_cursesi_screen->infd),
__tcaction ? TCSASOFT | TCSANOW : TCSANOW,
_cursesi_screen->curt) ? ERR : OK);
_cursesi_screen->curt)) {
__restore_termios();
return ERR;
}
return OK;
}
int