]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/read_termcap.c
ncurses 6.4 - patch 20240420
[ncurses.git] / ncurses / tinfo / read_termcap.c
index 418dc3f802551ab87ba63cb1a55a8cdd34fc74ea..1a294848b82732519adb681698e23e4af5a76246 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2018-2020,2021 Thomas E. Dickey                                *
+ * Copyright 2018-2021,2023 Thomas E. Dickey                                *
  * Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -57,7 +57,7 @@
 #include <sys/types.h>
 #include <tic.h>
 
-MODULE_ID("$Id: read_termcap.c,v 1.101 2021/06/26 19:43:17 tom Exp $")
+MODULE_ID("$Id: read_termcap.c,v 1.104 2023/06/24 21:53:16 tom Exp $")
 
 #if !PURE_TERMINFO
 
@@ -187,7 +187,7 @@ _nc_cgetcap(char *buf, const char *cap, int type)
     bp = buf;
     for (;;) {
        /*
-        * Skip past the current capability field - it's either the
+        * Skip past the current capability field - it is either the
         * name field if this is the first time through the loop, or
         * the remainder of a field whose name failed to match cap.
         */
@@ -324,7 +324,7 @@ _nc_getent(
            if (fd >= 0) {
                (void) lseek(fd, (off_t) 0, SEEK_SET);
            } else if ((_nc_access(db_array[current], R_OK) < 0)
-                      || (fd = open(db_array[current], O_RDONLY, 0)) < 0) {
+                      || (fd = safe_open2(db_array[current], O_RDONLY)) < 0) {
                /* No error on unfound file. */
                if (errno == ENOENT)
                    continue;
@@ -1055,15 +1055,15 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE2 *const tp)
     if (normal) {              /* normal case */
        char envhome[PATH_MAX], *h;
 
-       copied = strdup(get_termpath());
-       for (cp = copied; *cp; cp++) {
-           if (*cp == NCURSES_PATHSEP)
-               *cp = '\0';
-           else if (cp == copied || cp[-1] == '\0') {
-               ADD_TC(cp, filecount);
+       if ((copied = strdup(get_termpath())) != 0) {
+           for (cp = copied; *cp; cp++) {
+               if (*cp == NCURSES_PATHSEP)
+                   *cp = '\0';
+               else if (cp == copied || cp[-1] == '\0') {
+                   ADD_TC(cp, filecount);
+               }
            }
        }
-
 #define PRIVATE_CAP "%.*s/.termcap"
 
        if (use_terminfo_vars() && (h = getenv("HOME")) != NULL && *h != '\0'
@@ -1115,7 +1115,7 @@ _nc_read_termcap_entry(const char *const tn, TERMTYPE2 *const tp)
 
        /*
         * We don't suppress warning messages here.  The presumption is
-        * that since it's just a single entry, they won't be a pain.
+        * that since it is just a single entry, they won't be a pain.
         */
        _nc_read_entry_source((FILE *) 0, tc_buf, FALSE, FALSE, NULLHOOK);
        free(tc_buf);