Article View: comp.bugs.sys5
Article #61Bug in tgetent (3X) when TERMCAP=/foo/bar/termcap
From: Badger BA 64810
Date: Tue, 15 Aug 1989 19:06
Date: Tue, 15 Aug 1989 19:06
99 lines
3577 bytes
3577 bytes
SYMPTOM:
tcsh wouldn't find my personalized termcap entries, even when TERMCAP
was setenv'd to the correct file path.
PROBLEM:
tgetent expects the file descriptor returned from
tf = open(cp, 0);
to be non-zero. This isn't true when stdin is closed!
SOLUTION:
Use (-1) as the default flag value. This then indicates that either 1) No
attempt to open was made, or 2) the open failed.
DISCUSSION:
This was probably overlooked in testing because most programs are already
using file descriptor 0, and hence a successful open would return a
file descriptor other than zero. In my case stdin (fd 0) was closed, so
the successful open returned 0. This was mistakenly used by the program
to indicate that an open was not attempted.
The new code uses the standard
error return value of (-1) which is returned by a failed open.
**** I'm not absolutely certain that this is the correct behavior! ****
What it does is revert to the standard TERMCAP file if the open fails.
This certainly seems to be the right thing to do, but possibly not.
I *think* that the bug would also cause the standard termcap file to be
ignored in the case that the user provides an inaccessible TERMCAP file path.
In that case, tf is set to -1, and the standard file is not opened.
(My program didn't do this, so I'm giving my own interpretation of this
possibility.)
ALTERNATIVE:
GNU emacs comes with a version of termcap.c which does not seem to have
this problem. There are probably other public domain termcap.c
implementations to choose from.
PATCH:
--------- >8 --- cut here --- 8< ---------
diff -c V3.2.1/usr/src/lib/lxtermlib/termcap.c termcap.c
*** V3.2.1/usr/src/lib/lxtermlib/termcap.c Tue May 17 17:50:55 1988
--- termcap.c Tue Aug 15 09:21:24 1989
***************
*** 101,109 ****
char ibuf[BUFSIZ];
char *cp2;
int tf;
!
tbuf = bp;
! tf = 0;
#ifndef V6
cp = getenv("TERMCAP");
/*
--- 101,109 ----
char ibuf[BUFSIZ];
char *cp2;
int tf;
! #define OPEN_ERR (-1)
tbuf = bp;
! tf = OPEN_ERR;
#ifndef V6
cp = getenv("TERMCAP");
/*
***************
*** 126,137 ****
} else
tf = open(cp, 0);
}
! if (tf==0)
tf = open(E_TERMCAP, 0);
#else
tf = open(E_TERMCAP, 0);
#endif
! if (tf < 0)
return (-1);
for (;;) {
cp = bp;
--- 126,137 ----
} else
tf = open(cp, 0);
}
! if (tf==OPEN_ERR)
tf = open(E_TERMCAP, 0);
#else
tf = open(E_TERMCAP, 0);
#endif
! if (tf == OPEN_ERR)
return (-1);
for (;;) {
cp = bp;
--------- >8 --- cut here --- 8< ---------
Bernard A. Badger Jr. 407/984-6385 |``Use the Source, Luke!''
Secure Computer Products |``Get a LIFE!'' -- J.H. Conway
Harris GISD, Melbourne, FL 32902 |Buddy, can you paradigm?
Internet: bbadger%x102c@trantor.harris-atd.com|'s/./&&/g' Tom sed expansively.
Technical Details
Message-ID:
<2531@trantor.harris-atd.com>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!ucbvax!agate!helios.ee.lbl.gov!nosc!logicon.arpa!trantor.harris-atd.com!x102c!bbadgerShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!ucbvax!agate!helios.ee.lbl.gov!nosc!logicon.arpa!trantor.harris-atd.com!x102c!bbadger From: bbadger@x102c.harris-atd.com (Badger BA 64810) Newsgroups: comp.bugs.sys5 Subject: Bug in tgetent (3X) when TERMCAP=/foo/bar/termcap Summary: tgetent doesn't check files correctly Keywords: curses, termcap, tgetent Message-ID: <2531@trantor.harris-atd.com> Date: 15 Aug 89 19:06:55 GMT Sender: news@trantor.harris-atd.com Reply-To: bbadger@x102c.harris-atd.com Distribution: usa Organization: Harris GISD, Melbourne, FL Lines: 99