#include #include #include #include "stdio-util.h" typedef struct apriv APRIV; struct apriv { char *s; int l; char **sp; int *lp; } ; static int accum_w(void *pv, const char *buf, int len) { APRIV *p; p = pv; if (p->sp) { p->s = realloc(p->s,p->l+len); bcopy(buf,p->s+p->l,len); } p->l += len; return(len); } static int accum_c(void *pv) { APRIV *p; p = pv; if (p->sp) *p->sp = p->s; if (p->lp) *p->lp = p->l; free(p); return(0); } FILE *open_accum(char **sp, int *lp) { APRIV *p; FILE *f; p = malloc(sizeof(APRIV)); if (! p) return(0); f = funopen(p,0,&accum_w,0,&accum_c); if (! f) { free(p); return(0); } p->s = 0; p->l = 0; p->sp = sp; p->lp = lp; return(f); }