Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libcurses curses: don't optimize stdout buffer for non B...



details:   https://anonhg.NetBSD.org/src/rev/fb8cd630bde2
branches:  trunk
changeset: 836452:fb8cd630bde2
user:      roy <roy%NetBSD.org@localhost>
date:      Thu Oct 18 07:53:13 2018 +0000

description:
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.

diffstat:

 lib/libcurses/tstp.c |   7 +++++--
 lib/libcurses/tty.c  |  19 +++++++++++++++----
 2 files changed, 20 insertions(+), 6 deletions(-)

diffs (94 lines):

diff -r e4fa02e1579f -r fb8cd630bde2 lib/libcurses/tstp.c
--- a/lib/libcurses/tstp.c      Thu Oct 18 07:35:15 2018 +0000
+++ b/lib/libcurses/tstp.c      Thu Oct 18 07:53:13 2018 +0000
@@ -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 @@
        (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 -r e4fa02e1579f -r fb8cd630bde2 lib/libcurses/tty.c
--- a/lib/libcurses/tty.c       Thu Oct 18 07:35:15 2018 +0000
+++ b/lib/libcurses/tty.c       Thu Oct 18 07:53:13 2018 +0000
@@ -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 @@
 
        (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 @@
                        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);



Home | Main Index | Thread Index | Old Index