From 99898c775e90ebcef2ebce16fa6077ab88f42465 Mon Sep 17 00:00:00 2001 From: guenther Date: Sun, 20 Jul 2014 07:35:04 +0000 Subject: [PATCH] Eliminate trivial wrappers TerminalWrite() and TerminalRead() Replace TerminalFlushOutput() with tcflush(). Replace TerminalAutoFlush() with check of tty's NOFLSH flag as documented in the manpage. Push into .c files --- usr.bin/telnet/commands.c | 3 +- usr.bin/telnet/externs.h | 9 +----- usr.bin/telnet/sys_bsd.c | 53 ++---------------------------------- usr.bin/telnet/telnet_locl.h | 4 +-- usr.bin/telnet/terminal.c | 16 +++++++---- 5 files changed, 17 insertions(+), 68 deletions(-) diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c index 5e0f6a90086..a3e360b6d4e 100644 --- a/usr.bin/telnet/commands.c +++ b/usr.bin/telnet/commands.c @@ -1,4 +1,4 @@ -/* $OpenBSD: commands.c,v 1.60 2014/07/20 06:39:41 guenther Exp $ */ +/* $OpenBSD: commands.c,v 1.61 2014/07/20 07:35:04 guenther Exp $ */ /* $NetBSD: commands.c,v 1.14 1996/03/24 22:03:48 jtk Exp $ */ /* @@ -38,6 +38,7 @@ #include #include +#include #include #include #include diff --git a/usr.bin/telnet/externs.h b/usr.bin/telnet/externs.h index 4eb29ca0173..0ba00ae3d59 100644 --- a/usr.bin/telnet/externs.h +++ b/usr.bin/telnet/externs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: externs.h,v 1.20 2014/07/20 05:22:02 guenther Exp $ */ +/* $OpenBSD: externs.h,v 1.21 2014/07/20 07:35:04 guenther Exp $ */ /* $KTH: externs.h,v 1.16 1997/11/29 02:28:35 joda Exp $ */ /* @@ -196,14 +196,8 @@ int netflush(void); /* sys_bsd.c */ void init_sys(void); -int TerminalWrite(char *buf, int n); -int TerminalRead(unsigned char *buf, int n); -int TerminalAutoFlush(void); int TerminalSpecialChars(int c); -void TerminalFlushOutput(void); -void TerminalSaveState(void); void TerminalDefaultChars(void); -void TerminalNewMode(int f); cc_t *tcval(int func); void TerminalSpeeds(long *input_speed, long *output_speed); int TerminalWindowSize(long *rows, long *cols); @@ -242,7 +236,6 @@ void setneturg (void); void sys_telnet_init (void); void telnet (char *); void tel_enter_binary (int); -void TerminalFlushOutput (void); void TerminalNewMode (int); void TerminalRestoreState (void); void TerminalSaveState (void); diff --git a/usr.bin/telnet/sys_bsd.c b/usr.bin/telnet/sys_bsd.c index 8d0d3c66736..1c63e5db5a3 100644 --- a/usr.bin/telnet/sys_bsd.c +++ b/usr.bin/telnet/sys_bsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_bsd.c,v 1.18 2014/07/20 06:39:41 guenther Exp $ */ +/* $OpenBSD: sys_bsd.c,v 1.19 2014/07/20 07:35:04 guenther Exp $ */ /* $NetBSD: sys_bsd.c,v 1.11 1996/02/28 21:04:10 thorpej Exp $ */ /* @@ -64,39 +64,6 @@ init_sys() } - int -TerminalWrite(buf, n) - char *buf; - int n; -{ - return write(tout, buf, n); -} - - int -TerminalRead(buf, n) - unsigned char *buf; - int n; -{ - return read(tin, buf, n); -} - -/* - * - */ - - int -TerminalAutoFlush() -{ -#if defined(LNOFLSH) - int flush; - - ioctl(0, TIOCLGET, (char *)&flush); - return !(flush&LNOFLSH); /* if LNOFLSH, no autoflush */ -#else /* LNOFLSH */ - return 1; -#endif /* LNOFLSH */ -} - #ifdef KLUDGELINEMODE extern int kludgelinemode; #endif @@ -151,22 +118,6 @@ TerminalSpecialChars(c) return 1; } - -/* - * Flush output to the terminal - */ - - void -TerminalFlushOutput() -{ -#ifdef TIOCFLUSH - int com = FWRITE; - (void) ioctl(fileno(stdout), TIOCFLUSH, (int *) &com); -#else - (void) ioctl(fileno(stdout), TCFLSH, (int *) 0); -#endif -} - void TerminalSaveState() { @@ -828,7 +779,7 @@ process_rings(netin, netout, netex, ttyin, ttyout, dopoll) * Something to read from the tty... */ if (pfd[TELNET_FD_TIN].revents & (POLLIN|POLLHUP)) { - c = TerminalRead(ttyiring.supply, ring_empty_consecutive(&ttyiring)); + c = read(tin, ttyiring.supply, ring_empty_consecutive(&ttyiring)); if (c < 0 && errno == EIO) c = 0; if (c < 0 && errno == EWOULDBLOCK) { diff --git a/usr.bin/telnet/telnet_locl.h b/usr.bin/telnet/telnet_locl.h index 1522ed46cc7..a3c177f6fee 100644 --- a/usr.bin/telnet/telnet_locl.h +++ b/usr.bin/telnet/telnet_locl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: telnet_locl.h,v 1.7 2014/07/20 06:39:41 guenther Exp $ */ +/* $OpenBSD: telnet_locl.h,v 1.8 2014/07/20 07:35:04 guenther Exp $ */ /* $KTH: telnet_locl.h,v 1.13 1997/11/03 21:37:55 assar Exp $ */ /* @@ -43,8 +43,6 @@ #include #include -#include -#include #include #include #include diff --git a/usr.bin/telnet/terminal.c b/usr.bin/telnet/terminal.c index f096260d7ea..16d0b390d7d 100644 --- a/usr.bin/telnet/terminal.c +++ b/usr.bin/telnet/terminal.c @@ -1,4 +1,4 @@ -/* $OpenBSD: terminal.c,v 1.8 2014/07/20 06:24:19 guenther Exp $ */ +/* $OpenBSD: terminal.c,v 1.9 2014/07/20 07:35:04 guenther Exp $ */ /* $NetBSD: terminal.c,v 1.5 1996/02/28 21:04:17 thorpej Exp $ */ /* @@ -32,6 +32,8 @@ #include "telnet_locl.h" +#include + Ring ttyoring, ttyiring; unsigned char ttyobuf[2*BUFSIZ], ttyibuf[BUFSIZ]; @@ -75,9 +77,13 @@ cc_t termAytChar; void init_terminal() { + struct termios tc; + ring_init(&ttyoring, ttyobuf, sizeof ttyobuf); ring_init(&ttyiring, ttyibuf, sizeof ttyibuf); - autoflush = TerminalAutoFlush(); + + tcgetattr(0, &tc); + autoflush = (tc.c_lflag & NOFLSH) == 0; } @@ -101,10 +107,10 @@ ttyflush(drop) n0 = ring_full_count(&ttyoring); if ((n1 = n = ring_full_consecutive(&ttyoring)) > 0) { if (drop) { - TerminalFlushOutput(); + tcflush(fileno(stdout), TCOFLUSH); /* we leave 'n' alone! */ } else { - n = TerminalWrite((char *)ttyoring.consume, n); + n = write(tout, ttyoring.consume, n); } } if (n > 0) { @@ -119,7 +125,7 @@ ttyflush(drop) if (n1 == n && n0 > n) { n1 = n0 - n; if (!drop) - n1 = TerminalWrite(ttyoring.bottom, n1); + n1 = write(tout, ttyoring.bottom, n1); if (n1 > 0) n += n1; } -- 2.20.1