28 |
|
#define MINRUN 4 /* minimum run length */ |
29 |
|
|
30 |
|
|
31 |
< |
char * |
31 |
> |
void * |
32 |
|
tempbuffer( /* get a temporary buffer */ |
33 |
|
unsigned int len |
34 |
|
) |
35 |
|
{ |
36 |
< |
static char *tempbuf = NULL; |
37 |
< |
static unsigned tempbuflen = 0; |
36 |
> |
static void *tempbuf = NULL; |
37 |
> |
static unsigned int tempbuflen = 0; |
38 |
|
|
39 |
< |
if (!len | (len > tempbuflen)) { |
40 |
< |
if (tempbuflen) |
39 |
> |
if (!len) { /* call to free */ |
40 |
> |
if (tempbuflen) { |
41 |
|
free(tempbuf); |
42 |
< |
tempbuf = len ? (char *)malloc(len) : (char *)NULL; |
43 |
< |
tempbuflen = len*(tempbuf != NULL); |
42 |
> |
tempbuf = NULL; |
43 |
> |
tempbuflen = 0; |
44 |
> |
} |
45 |
> |
return(NULL); |
46 |
|
} |
47 |
+ |
if (len <= tempbuflen) /* big enough already? */ |
48 |
+ |
return(tempbuf); |
49 |
+ |
/* else free & reallocate */ |
50 |
+ |
if (tempbuflen) |
51 |
+ |
free(tempbuf); |
52 |
+ |
tempbuf = malloc(len); |
53 |
+ |
tempbuflen = len*(tempbuf != NULL); |
54 |
|
return(tempbuf); |
55 |
|
} |
56 |
|
|