--- Revision 5614 +++ Revision 5620 @@ -58,12 +58,33 @@ } -static inline void cw_dynstr_free(struct cw_dynstr *ds) +static inline void cw_dynstr_reset(struct cw_dynstr **ds_p) { - free(ds); + (*ds_p)->used = 0; + (*ds_p)->error = 0; } +extern CW_API_PUBLIC int cw_dynstr_grow(struct cw_dynstr **ds_p, size_t len) + __attribute__ ((nonnull (1))); + + +static inline int cw_dynstr_need(struct cw_dynstr **ds_p, size_t len) +{ + len += (*ds_p)->used; + if (len > (*ds_p)->size) + cw_dynstr_grow(ds_p, len); + return (*ds_p)->error; +} + + +static inline void cw_dynstr_free(struct cw_dynstr **ds) +{ + free(*ds); + *ds = NULL; +} + + extern CW_API_PUBLIC int cw_dynstr_vprintf(struct cw_dynstr **ds_p, const char *fmt, va_list ap) __attribute__ ((__nonnull__ (1,2))); extern CW_API_PUBLIC int cw_dynstr_printf(struct cw_dynstr **ds_p, const char *fmt, ...)