[comp.sources.d] termcap.c BUG; affects tcsh

mark@hyper.UUCP (Mark Mendel) (08/13/87)

There is an obscure bug in the termlib/termcap library.  Tgetent() uses 0 as an
invalid return value from open(). This works fine unless stdin has been closed.
Tcsh does this on startup.  The result is that the value of your TERMCAP 
variable is not used if it is a file.

Here is the fix:

*** termcap.c.orig	Thu Aug 13 14:25:48 1987
--- termcap.c	Thu Aug 13 14:28:56 1987
***************
*** 44,50
  	int tf;
  
  	tbuf = bp;
! 	tf = 0;
  #ifndef V6
  	cp = getenv("TERMCAP");
  	/*

--- 44,50 -----
  	int tf;
  
  	tbuf = bp;
! 	tf = -1;
  #ifndef V6
  	cp = getenv("TERMCAP");
  	/*
***************
*** 66,72
  		} else
  			tf = open(cp, 0);
  	}
! 	if (tf==0)
  		tf = open(E_TERMCAP, 0);
  #else
  	tf = open(E_TERMCAP, 0);

--- 66,72 -----
  		} else
  			tf = open(cp, 0);
  	}
! 	if (tf==-1)
  		tf = open(E_TERMCAP, 0);
  #else
  	tf = open(E_TERMCAP, 0);
-- 
Mark G. Mendel, ihnp4!umn-cs!hyper!mark,  Network Systems Corporation
(612)-424-4888 x2779