# include <sys/ioctl.h>
# endif /* HAVE_TERMIO_H */
#endif /* HAVE_TERMIOS_H */
-#include <errno.h>
#include "sudo.h"
term_restore(fd)
int fd;
{
- int rval;
-
if (changed) {
- do {
- rval = tcsetattr(fd, TCSAFLUSH|TCSASOFT, &oterm);
- } while (rval == -1 && errno == EINTR);
- if (rval)
+ if (tcsetattr(fd, TCSAFLUSH|TCSASOFT, &oterm) != 0)
return(0);
changed = 0;
}
term_noecho(fd)
int fd;
{
- int rval;
-
- if (!changed) {
- do {
- rval = tcgetattr(fd, &oterm);
- } while (rval == -1 && errno == EINTR);
- if (rval)
- return(0);
- }
+ if (!changed && tcgetattr(fd, &oterm) != 0)
+ return(0);
(void) memcpy(&term, &oterm, sizeof(term));
CLR(term.c_lflag, ECHO|ECHONL);
#ifdef VSTATUS
term.c_cc[VSTATUS] = _POSIX_VDISABLE;
#endif
- do {
- rval = tcsetattr(fd, TCSAFLUSH|TCSASOFT, &term);
- } while (rval == -1 && errno == EINTR);
- if (rval)
- return(0);
- changed = 1;
- return(1);
+ if (tcsetattr(fd, TCSAFLUSH|TCSASOFT, &term) == 0) {
+ changed = 1;
+ return(1);
+ }
+ return(0);
}
#if defined(HAVE_TERMIOS_H) || defined(HAVE_TERMIO_H)
int onlcr;
{
struct termios term;
- int rval;
- if (!changed) {
- do {
- rval = tcgetattr(fd, &oterm);
- } while (rval == -1 && errno == EINTR);
- if (rval)
- return(0);
- }
+ if (!changed && tcgetattr(fd, &oterm) != 0)
+ return(0);
(void) memcpy(&term, &oterm, sizeof(term));
/* Set terminal to raw mode */
term.c_iflag &= ~(ICRNL|IGNCR|INLCR|IUCLC|IXON);
term.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
term.c_cc[VMIN] = 1;
term.c_cc[VTIME] = 0;
- do {
- rval = tcsetattr(fd, TCSAFLUSH|TCSASOFT, &term);
- } while (rval == -1 && errno == EINTR);
- if (rval)
- return(0);
- changed = 1;
- return(1);
+ if (tcsetattr(fd, TCSAFLUSH|TCSASOFT, &term) == 0) {
+ changed = 1;
+ return(1);
+ }
+ return(0);
}
int
term_cbreak(fd)
int fd;
{
- int rval;
-
- if (!changed) {
- do {
- rval = tcgetattr(fd, &oterm);
- } while (rval == -1 && errno == EINTR);
- if (rval)
- return(0);
- }
+ if (!changed && tcgetattr(fd, &oterm) != 0)
+ return(0);
(void) memcpy(&term, &oterm, sizeof(term));
/* Set terminal to half-cooked mode */
term.c_cc[VMIN] = 1;
#ifdef VSTATUS
term.c_cc[VSTATUS] = _POSIX_VDISABLE;
#endif
- do {
- rval = tcsetattr(fd, TCSAFLUSH|TCSASOFT, &term);
- } while (rval == -1 && errno == EINTR);
- if (rval)
- return(0);
- term_erase = term.c_cc[VERASE];
- term_kill = term.c_cc[VKILL];
- changed = 1;
- return(1);
+ if (tcsetattr(fd, TCSAFLUSH|TCSASOFT, &term) == 0) {
+ term_erase = term.c_cc[VERASE];
+ term_kill = term.c_cc[VKILL];
+ changed = 1;
+ return(1);
+ }
+ return(0);
}
int
int onlcr;
{
struct termios tt;
- int rval;
- do {
- rval = tcgetattr(src, &tt);
- } while (rval == -1 && errno == EINTR);
- if (rval)
+ if (tcgetattr(src, &tt) != 0)
return(0);
/* Do not convert line endings from NL to NLCR. */
if (!onlcr)
CLR(tt.c_oflag, ONLCR);
- do {
- rval = tcsetattr(dst, TCSAFLUSH|TCSASOFT, &tt);
- } while (rval == -1 && errno == EINTR);
- if (rval)
+ if (tcsetattr(dst, TCSAFLUSH|TCSASOFT, &tt) != 0)
return(0);
return(1);
}
int fd;
int onlcr;
{
- int rval;
-
- if (!changed) {
- do {
- rval = ioctl(fd, TIOCGETP, &oterm);
- } while (rval == -1 && errno == EINTR);
- if (rval)
- return(0);
- }
+ if (!changed && ioctl(fd, TIOCGETP, &oterm) != 0)
+ return(0);
(void) memcpy(&term, &oterm, sizeof(term));
/* Set terminal to raw mode */
CLR(term.c_lflag, ECHO);
/* Retain NL to NLCR conversion if onlcr flag set. */
if (onlcr)
SET(term.sg_flags, CRMOD);
- do {
- rval = ioctl(fd, TIOCSETP, &term);
- } while (rval == -1 && errno == EINTR);
- if (rval)
- return(0);
- changed = 1;
- return(1);
+ if (ioctl(fd, TIOCSETP, &term) == 0) {
+ changed = 1;
+ return(1);
+ }
+ return(0);
}
int
term_cbreak(fd)
int fd;
{
- int rval;
-
- if (!changed) {
- do {
- rval = ioctl(fd, TIOCGETP, &oterm);
- } while (rval == -1 && errno == EINTR);
- if (rval)
- return(0);
- }
+ if (!changed && ioctl(fd, TIOCGETP, &oterm) != 0)
+ return(0);
(void) memcpy(&term, &oterm, sizeof(term));
/* Set terminal to half-cooked mode */
CLR(term.c_lflag, ECHO);
SET(term.sg_flags, CBREAK);
- do {
- rval = ioctl(fd, TIOCSETP, &term);
- } while (rval == -1 && errno == EINTR);
- if (rval)
- return(0);
- term_erase = term.sg_erase;
- term_kill = term.sg_kill;
- changed = 1;
- return(1);
+ if (ioctl(fd, TIOCSETP, &term) == 0) {
+ term_erase = term.sg_erase;
+ term_kill = term.sg_kill;
+ changed = 1;
+ return(1);
+ }
+ return(0);
}
int
struct ltchars lc;
int l, lb;
- /* XXX - handle EINTR */
if (ioctl(src, TIOCGETP, &b) != 0 || ioctl(src, TIOCGETC, &tc) != 0 ||
ioctl(src, TIOCGETD, &l) != 0 || ioctl(src, TIOCGLTC, &lc) != 0 ||
ioctl(src, TIOCLGET, &lb)) {