#include #include #include #include "stdio-util.h" typedef struct allocblk ALLOCBLK; struct allocblk { char **bufp; int *lenp; char *buf; int len; } ; static int alloc_w(void *av, const char *b, int l) { ALLOCBLK *a; a = av; a->buf = realloc(a->buf,a->len+l); bcopy(b,a->buf+a->len,l); a->len += l; return(l); } static int alloc_c(void *av) { ALLOCBLK *a; a = av; *a->bufp = a->buf; *a->lenp = a->len; free(a); return(0); } FILE *fopen_alloc(char **bufp, int *lenp) { FILE *f; ALLOCBLK *a; a = malloc(sizeof(ALLOCBLK)); if (a == 0) return(0); a->bufp = bufp; a->lenp = lenp; a->buf = 0; a->len = 0; f = funopen(a,0,&alloc_w,0,&alloc_c); if (f == 0) free(a); return(f); }