Replace TerminalFlushOutput() with tcflush().
Replace TerminalAutoFlush() with check of tty's NOFLSH flag as
documented in the manpage.
Push <netdb.h> into .c files
-/* $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 $ */
/*
#include <ctype.h>
#include <err.h>
+#include <netdb.h>
#include <pwd.h>
#include <stdarg.h>
#include <unistd.h>
-/* $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 $ */
/*
/* 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);
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);
-/* $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 $ */
/*
}
- 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
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()
{
* 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) {
-/* $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 $ */
/*
#include <sys/socket.h>
#include <errno.h>
-#include <fcntl.h>
-#include <netdb.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
-/* $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 $ */
/*
#include "telnet_locl.h"
+#include <unistd.h>
+
Ring ttyoring, ttyiring;
unsigned char ttyobuf[2*BUFSIZ], ttyibuf[BUFSIZ];
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;
}
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) {
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;
}