Source-Changes-HG archive

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

[src/trunk]: src/lib/libterminfo terminfo: if $TERMINFO.cdb doesn't exist, tr...



details:   https://anonhg.NetBSD.org/src/rev/ad3dd5a474d7
branches:  trunk
changeset: 433884:ad3dd5a474d7
user:      roy <roy%NetBSD.org@localhost>
date:      Mon Oct 08 20:44:34 2018 +0000

description:
terminfo: if $TERMINFO.cdb doesn't exist, try $TERMINFO

This allows this command sequence to work:
tic -o /tmp/foo foo
TERMINFO=/tmp/foo TERM=foo infocmp

diffstat:

 lib/libterminfo/term.c |  20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diffs (41 lines):

diff -r 6a2b884d8de7 -r ad3dd5a474d7 lib/libterminfo/term.c
--- a/lib/libterminfo/term.c    Mon Oct 08 18:01:23 2018 +0000
+++ b/lib/libterminfo/term.c    Mon Oct 08 20:44:34 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: term.c,v 1.28 2017/05/16 12:03:41 roy Exp $ */
+/* $NetBSD: term.c,v 1.29 2018/10/08 20:44:34 roy Exp $ */
 
 /*
  * Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: term.c,v 1.28 2017/05/16 12:03:41 roy Exp $");
+__RCSID("$NetBSD: term.c,v 1.29 2018/10/08 20:44:34 roy Exp $");
 
 #include <sys/stat.h>
 
@@ -284,9 +284,19 @@
        size_t len, klen;
        int r;
 
-       if (snprintf(__ti_database, sizeof(__ti_database), "%s.cdb", path) < 0)
-               return -1;
-       db = cdbr_open(__ti_database, CDBR_DEFAULT);
+       r = snprintf(__ti_database, sizeof(__ti_database), "%s.cdb", path);
+       if (r < 0 || (size_t)r > sizeof(__ti_database)) {
+               db = NULL;
+               errno = ENOENT; /* To fall back to a non extension. */
+       } else
+               db = cdbr_open(__ti_database, CDBR_DEFAULT);
+
+       /* Target file *may* be a cdb file without the extension. */
+       if (db == NULL && errno == ENOENT) {
+               len = strlcpy(__ti_database, path, sizeof(__ti_database));
+               if (len < sizeof(__ti_database))
+                       db = cdbr_open(__ti_database, CDBR_DEFAULT);
+       }
        if (db == NULL)
                return -1;
 



Home | Main Index | Thread Index | Old Index