diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1998-09-13 19:16:32 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1998-09-13 19:16:32 +0000 |
commit | 53218c15edcfe41c06028f1a17a68693bb6bc556 (patch) | |
tree | 1d0df32b127f247ba83c0a8cc104156535f70408 /lib/libcurses/trace_buf.c | |
parent | 777adf5023503ad1519db23336d1e411ba8fa089 (diff) |
ncurses-4.2-980905
Diffstat (limited to 'lib/libcurses/trace_buf.c')
-rw-r--r-- | lib/libcurses/trace_buf.c | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/lib/libcurses/trace_buf.c b/lib/libcurses/trace_buf.c index a096fc7a9f8..0fad3c81040 100644 --- a/lib/libcurses/trace_buf.c +++ b/lib/libcurses/trace_buf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trace_buf.c,v 1.4 1998/08/15 18:44:46 millert Exp $ */ +/* $OpenBSD: trace_buf.c,v 1.5 1998/09/13 19:16:31 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -37,14 +37,16 @@ #include <curses.priv.h> -MODULE_ID("$From: trace_buf.c,v 1.5 1998/05/30 23:30:09 Todd.Miller Exp $") +MODULE_ID("$From: trace_buf.c,v 1.6 1998/08/15 23:37:25 tom Exp $") + +typedef struct { + char *text; + size_t size; +} LIST; char * _nc_trace_buf(int bufnum, size_t want) { - static struct { - char *text; - size_t size; - } *list, *nlist; + static LIST *list; static size_t have; #if NO_LEAKS @@ -62,33 +64,19 @@ char * _nc_trace_buf(int bufnum, size_t want) if ((size_t)(bufnum+1) > have) { size_t need = (bufnum + 1) * 2; size_t used = sizeof(*list) * need; - nlist = (list == 0) ? malloc(used) : realloc(list, used); - if (nlist == 0) { - if (list != 0) - free(list); - return(NULL); - } - list = nlist; + if ((list = (LIST *)_nc_doalloc(list, used)) == 0) + return(0); while (need > have) list[have++].text = 0; } - if (list[bufnum].text == 0) + if (list[bufnum].text == 0 + || want > list[bufnum].size) { - list[bufnum].text = malloc(want); + if ((list[bufnum].text = (char *)_nc_doalloc(list[bufnum].text, want)) != 0) + list[bufnum].size = want; } - else if (want > list[bufnum].size) - { - void *p = realloc(list[bufnum].text, want); - if (p != 0) { - list[bufnum].text = p; - } else { - free(list[bufnum].text); - list[bufnum].text = 0; - } - } - list[bufnum].size = want; if (list[bufnum].text != 0) *(list[bufnum].text) = '\0'; return list[bufnum].text; |