]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/trace/trace_buf.c
ncurses 5.0
[ncurses.git] / ncurses / trace / trace_buf.c
similarity index 85%
rename from ncurses/trace_buf.c
rename to ncurses/trace/trace_buf.c
index 688ee3eee3d53051987fd3b9296c9a4a619e0d5a..48f93d43d1ef1a45d204da0ca895346ad188dd6e 100644 (file)
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: trace_buf.c,v 1.3 1998/02/11 12:13:55 tom Exp $")
+MODULE_ID("$Id: trace_buf.c,v 1.7 1999/02/27 19:50:58 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;
+       static LIST *list;
        static size_t have;
 
 #if NO_LEAKS
@@ -59,21 +61,20 @@ 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;
-               list = (list == 0) ? malloc(used) : realloc(list, used);
+               if ((list = typeRealloc(LIST, need, list)) == 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);
-               list[bufnum].size = want;
-       }
-       else if (want > list[bufnum].size) {
-               list[bufnum].text = realloc(list[bufnum].text, want);
-               list[bufnum].size = want;
+               if ((list[bufnum].text = typeRealloc(char, want, list[bufnum].text)) != 0)
+                       list[bufnum].size = want;
        }
-       *(list[bufnum].text) = '\0';
+
+       if (list[bufnum].text != 0)
+               *(list[bufnum].text) = '\0';
        return list[bufnum].text;
 }