From 540421553f5afafa1df8d51bd530c6c12fa8fd10 Mon Sep 17 00:00:00 2001 From: blymn Date: Tue, 17 Aug 1999 12:13:24 +0000 Subject: [PATCH] Added minor tweak to t_getstr, by passing a NULL area pointer the size of the requested capability will be returned in the limit parameter. --- lib/libterm/termcap.3 | 19 ++++++++++++------- lib/libterm/termcap.c | 27 ++++++++++++++++----------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/lib/libterm/termcap.3 b/lib/libterm/termcap.3 index 4cc92403adec..c420e9ff3e51 100644 --- a/lib/libterm/termcap.3 +++ b/lib/libterm/termcap.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: termcap.3,v 1.14 1999/08/16 08:34:33 blymn Exp $ +.\" $NetBSD: termcap.3,v 1.15 1999/08/17 12:13:24 blymn Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -311,6 +311,12 @@ there was no termcap entry for the given .Fa id , E2BIG indicates the retrieved entry would have overflowed .Fa area . +If t_getstr is called with +.Fa area +being NULL then the size required to hold the capability string will be +returned in +.Fa limit +so the caller can allocate enough storage to hold the capability. .Pp The .Fn t_goto @@ -366,13 +372,12 @@ argument. The interpretation of the contents of is dependent soley on the implementation of .Fa outc. .Pp -NOTE: If the termcap entry would exceed the 1024 buffer passed to -.Fa tgetent -then a special capability of +NOTE: A special capability of .Fa ZZ -is added to the end of the termcap. The number that follows this entry -is the address of the buffer allocated to hold the full termcap entry. The -caller may retrieve the pointer to the extended buffer by performing a +is added to the end of the termcap entry retrieved. The number that follows +this entry is the address of the buffer allocated to hold the full termcap +entry. The caller may retrieve the pointer to the extended buffer by +performing a .Fn tgetstr to retrieve the .Fa ZZ diff --git a/lib/libterm/termcap.c b/lib/libterm/termcap.c index 79312966bb9a..3788f5f1c1f8 100644 --- a/lib/libterm/termcap.c +++ b/lib/libterm/termcap.c @@ -1,4 +1,4 @@ -/* $NetBSD: termcap.c,v 1.19 1999/08/16 08:34:33 blymn Exp $ */ +/* $NetBSD: termcap.c,v 1.20 1999/08/17 12:13:24 blymn Exp $ */ /* * Copyright (c) 1980, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: termcap.c,v 1.19 1999/08/16 08:34:33 blymn Exp $"); +__RCSID("$NetBSD: termcap.c,v 1.20 1999/08/17 12:13:24 blymn Exp $"); #endif #endif /* not lint */ @@ -291,17 +291,22 @@ t_getstr(info, id, area, limit) return NULL; } - /* check if there is room for the new entry to be put into area */ - if (limit != NULL && (*limit < i)) { - errno = E2BIG; + if (area != NULL) { + /* check if there is room for the new entry to be put into area */ + if (limit != NULL && (*limit < i)) { + errno = E2BIG; + return NULL; + } + + strcpy(*area, s); + *area += i + 1; + if (limit != NULL) *limit -= i; + + return (s); + } else { + *limit = i; return NULL; } - - strcpy(*area, s); - *area += i + 1; - if (limit != NULL) *limit -= i; - - return (s); } /*