]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_setup.c
ncurses 6.4 - patch 20230805
[ncurses.git] / ncurses / tinfo / lib_setup.c
index 9c8b44aaea681b49e218e319a71afb4b9fab63f6..ed93378c6f29a854130ecc94cfd83db75119b99e 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2018-2020,2021 Thomas E. Dickey                                *
+ * Copyright 2018-2022,2023 Thomas E. Dickey                                *
  * Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -49,7 +49,7 @@
 #include <locale.h>
 #endif
 
-MODULE_ID("$Id: lib_setup.c,v 1.213 2021/03/20 14:43:35 tom Exp $")
+MODULE_ID("$Id: lib_setup.c,v 1.221 2023/07/22 20:13:04 tom Exp $")
 
 /****************************************************************************
  *
@@ -66,7 +66,7 @@ MODULE_ID("$Id: lib_setup.c,v 1.213 2021/03/20 14:43:35 tom Exp $")
 #endif
 
 #if NEED_PTEM_H
- /* On SCO, they neglected to define struct winsize in termios.h -- it's only
+ /* On SCO, they neglected to define struct winsize in termios.h -- it is only
   * in termio.h and ptem.h (the former conflicts with other definitions).
   */
 # include <sys/stream.h>
@@ -679,10 +679,9 @@ TINFO_SETUP_TERM(TERMINAL **tp,
 #endif
     }
     myname = strdup(tname);
-
-    if (strlen(myname) > MAX_NAME_SIZE) {
+    if (myname == NULL || strlen(myname) > MAX_NAME_SIZE) {
        ret_error(TGETENT_ERR,
-                 "TERM environment must be <= %d characters.\n",
+                 "TERM environment must be 1..%d characters.\n",
                  MAX_NAME_SIZE,
                  free(myname));
     }
@@ -743,6 +742,7 @@ TINFO_SETUP_TERM(TERMINAL **tp,
                       "Not enough memory to create terminal structure.\n",
                       myname, free(myname));
        }
+       ++_nc_globals.terminal_count;
 #if HAVE_SYSCONF
        {
            long limit;
@@ -763,10 +763,14 @@ TINFO_SETUP_TERM(TERMINAL **tp,
 
 #ifdef USE_TERM_DRIVER
        INIT_TERM_DRIVER();
+       /*
+        * _nc_get_driver() will call td_CanHandle() for each driver, and win_driver
+        * needs file descriptor to do the test, so set it before calling.
+        */
+       termp->Filedes = (short) Filedes;
        TCB = (TERMINAL_CONTROL_BLOCK *) termp;
        code = _nc_globals.term_driver(TCB, myname, errret);
        if (code == OK) {
-           termp->Filedes = (short) Filedes;
            termp->_termname = strdup(myname);
        } else {
            ret_error1(errret ? *errret : TGETENT_ERR,
@@ -830,7 +834,7 @@ TINFO_SETUP_TERM(TERMINAL **tp,
        if (NC_ISATTY(Filedes)) {
            NCURSES_SP_NAME(def_shell_mode) (NCURSES_SP_ARG);
            NCURSES_SP_NAME(def_prog_mode) (NCURSES_SP_ARG);
-           baudrate();
+           NCURSES_SP_NAME(baudrate) (NCURSES_SP_ARG);
        }
        code = OK;
 #endif
@@ -907,6 +911,7 @@ _nc_forget_prescr(void)
 {
     PRESCREEN_LIST *p, *q;
     pthread_t id = GetThreadID();
+    _nc_lock_global(screen);
     for (p = _nc_prescreen.allocated, q = 0; p != 0; q = p, p = p->next) {
        if (p->id == id) {
            if (q) {
@@ -918,6 +923,7 @@ _nc_forget_prescr(void)
            break;
        }
     }
+    _nc_unlock_global(screen);
 }
 #endif /* USE_PTHREADS */
 
@@ -989,6 +995,7 @@ _nc_setupterm(const char *tname,
     int rc = ERR;
     TERMINAL *termp = 0;
 
+    _nc_init_pthreads();
     _nc_lock_global(prescreen);
     START_TRACE();
     if (TINFO_SETUP_TERM(&termp, tname, Filedes, errret, reuse) == OK) {
@@ -998,6 +1005,7 @@ _nc_setupterm(const char *tname,
        }
     }
     _nc_unlock_global(prescreen);
+
     return rc;
 }
 #endif