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.
This commit is contained in:
parent
3939637324
commit
501d84b3ab
@ -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 <sys/ioctl.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
@ -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;
|
||||
|
||||
|
@ -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 <sys/fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#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);
|
||||
|
Loading…
Reference in New Issue
Block a user