From 501d84b3ab1393c3af9f89018ea64010c15132b6 Mon Sep 17 00:00:00 2001 From: roy Date: Thu, 18 Oct 2018 07:53:13 +0000 Subject: [PATCH] curses: don't optimize stdout buffer for non BSD platforms The way BSD setvbuf works is not portable and should not be relied on. This is only important if curses is started, stopped and started in the same session which is how portable applications handle terminal resizing. --- lib/libcurses/tstp.c | 7 +++++-- lib/libcurses/tty.c | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/libcurses/tstp.c b/lib/libcurses/tstp.c index 5e90a04f00de..f0baa999120b 100644 --- a/lib/libcurses/tstp.c +++ b/lib/libcurses/tstp.c @@ -1,4 +1,4 @@ -/* $NetBSD: tstp.c,v 1.43 2018/09/18 22:51:00 rin Exp $ */ +/* $NetBSD: tstp.c,v 1.44 2018/10/18 07:53:13 roy Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -34,11 +34,12 @@ #if 0 static char sccsid[] = "@(#)tstp.c 8.3 (Berkeley) 5/4/94"; #else -__RCSID("$NetBSD: tstp.c,v 1.43 2018/09/18 22:51:00 rin Exp $"); +__RCSID("$NetBSD: tstp.c,v 1.44 2018/10/18 07:53:13 roy Exp $"); #endif #endif /* not lint */ #include +#include #include #include @@ -252,7 +253,9 @@ __stopwin(void) (void)tputs(cursor_normal, 0, __cputchar); (void)tputs(exit_ca_mode, 0, __cputchar); (void)fflush(_cursesi_screen->outfd); +#ifdef BSD (void)setvbuf(_cursesi_screen->outfd, NULL, _IOLBF, 0); +#endif _cursesi_screen->endwin = 1; diff --git a/lib/libcurses/tty.c b/lib/libcurses/tty.c index d83ffc2c62e1..fca9f179c1ba 100644 --- a/lib/libcurses/tty.c +++ b/lib/libcurses/tty.c @@ -1,4 +1,4 @@ -/* $NetBSD: tty.c,v 1.46 2017/01/06 13:53:18 roy Exp $ */ +/* $NetBSD: tty.c,v 1.47 2018/10/18 07:53:13 roy Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -34,17 +34,18 @@ #if 0 static char sccsid[] = "@(#)tty.c 8.6 (Berkeley) 1/10/95"; #else -__RCSID("$NetBSD: tty.c,v 1.46 2017/01/06 13:53:18 roy Exp $"); +__RCSID("$NetBSD: tty.c,v 1.47 2018/10/18 07:53:13 roy Exp $"); #endif #endif /* not lint */ +#include +#include +#include #include #include #include #include -#include -#include #include "curses.h" #include "curses_private.h" @@ -545,12 +546,21 @@ __startwin(SCREEN *screen) (void)fflush(screen->infd); +#ifdef BSD /* * Some C libraries default to a 1K buffer when talking to a tty. * With a larger screen, especially across a network, we'd like * to get it to all flush in a single write. Make it twice as big * as just the characters (so that we have room for cursor motions * and attribute information) but no more than 8K. + * + * However, setvbuf may only be used after opening a stream and + * before any operations have been performed on it. + * This means we cannot work portably if an application wants + * to stop curses and start curses after a resize. + * Curses resizing is not standard, and thus not strictly portable + * even though all curses today support it. + * The BSD systems do not suffer from this limitation on setvbuf. */ if (screen->stdbuf == NULL) { screen->len = LINES * COLS * 2; @@ -560,6 +570,7 @@ __startwin(SCREEN *screen) screen->len = 0; } (void)setvbuf(screen->outfd, screen->stdbuf, _IOFBF, screen->len); +#endif ti_puts(screen->term, t_enter_ca_mode(screen->term), 0, __cputchar_args, (void *) screen->outfd);