Only add the ZZ capability for termcap entries that are larger than 1023

bytes.

This fixes the problem that enabling the titeInhibit Xresource of xterm has
no effect, because xterm exports a TERMCAP string without ti/te sequences
but doesn't remove the ZZ capability because it doesn't know about it and
termcap(3) ignores the stringe because of the ZZ.

Discussed with and OK'ed by blymn@.
This commit is contained in:
bad 2009-03-02 22:46:21 +00:00
parent bae4fdf17e
commit adb98feec9
2 changed files with 26 additions and 22 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: termcap.3,v 1.32 2006/12/18 13:27:25 kleink Exp $
.\" $NetBSD: termcap.3,v 1.33 2009/03/02 22:46:21 bad Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -468,7 +468,8 @@ The format of the string
.Fa entry
is assumed to be a valid termcap entry.
.Pp
NOTE: A special capability of
NOTE: For termcap entries that are larger than 1023 bytes a special
capability of
.Fa ZZ
is added to the end of the termcap entry retrieved.
The number that follows this entry is the address of the buffer allocated

View File

@ -1,4 +1,4 @@
/* $NetBSD: termcap.c,v 1.54 2006/12/19 02:02:03 uwe Exp $ */
/* $NetBSD: termcap.c,v 1.55 2009/03/02 22:46:21 bad Exp $ */
/*
* Copyright (c) 1980, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: termcap.c,v 1.54 2006/12/19 02:02:03 uwe Exp $");
__RCSID("$NetBSD: termcap.c,v 1.55 2009/03/02 22:46:21 bad Exp $");
#endif
#endif /* not lint */
@ -281,29 +281,32 @@ tgetent(char *bp, const char *name)
if (i == 1) {
/*
* if the termcap entry is larger than 1023 bytes,
* stash the full buffer pointer as the ZZ capability
* in the termcap buffer passed.
*/
plen = asprintf(&ptrbuf, ":ZZ=%p", fbuf->info);
(void)strlcpy(bp, fbuf->info, 1024);
elen = strlen(bp);
/*
* backup over the entry if the addition of the full
* buffer pointer will overflow the buffer passed. We
* want to truncate the termcap entry on a capability
* boundary.
*/
if ((elen + plen) > 1023) {
bp[1023 - plen] = '\0';
for (c = (elen - plen); c > 0; c--) {
if (bp[c] == ':') {
bp[c] = '\0';
break;
if (strlcpy(bp, fbuf->info, 1024) >= 1024) {
plen = asprintf(&ptrbuf, ":ZZ=%p", fbuf->info);
(void)strlcpy(bp, fbuf->info, 1024);
elen = strlen(bp);
/*
* backup over the entry if the addition of the full
* buffer pointer will overflow the buffer passed. We
* want to truncate the termcap entry on a capability
* boundary.
*/
if ((elen + plen) > 1023) {
bp[1023 - plen] = '\0';
for (c = (elen - plen); c > 0; c--) {
if (bp[c] == ':') {
bp[c] = '\0';
break;
}
}
}
}
strcat(bp, ptrbuf);
}
strcat(bp, ptrbuf);
}
tbuf = bp;
}