/* * Extend an vsb. */ static ssize_t VSB_extend(struct vsb *s, ssize_t addlen) { char *newbuf; ssize_t newsize; if (!VSB_CANEXTEND(s)) return (-1); newsize = VSB_extendsize(s->s_size + addlen); if (VSB_ISDYNAMIC(s)) newbuf = realloc(s->s_buf, newsize); else newbuf = SBMALLOC(newsize); if (newbuf == NULL) return (-1); if (!VSB_ISDYNAMIC(s)) { memcpy(newbuf, s->s_buf, s->s_size); VSB_SETFLAG(s, VSB_DYNAMIC); } s->s_buf = newbuf; s->s_size = newsize; return (0); }
/* * Clear an vsb, free its buffer if necessary. */ void VSB_delete(struct vsb *s) { int isdyn; assert_VSB_integrity(s); /* don't care if it's finished or not */ if (VSB_ISDYNAMIC(s)) SBFREE(s->s_buf); isdyn = VSB_ISDYNSTRUCT(s); memset(s, 0, sizeof(*s)); if (isdyn) SBFREE(s); }
/* * Extend an vsb. */ static int VSB_extend(struct vsb *s, int addlen) { char *newbuf; int newsize; if (!VSB_CANEXTEND(s)) return (-1); newsize = VSB_extendsize(s->s_size + addlen); newbuf = SBMALLOC(newsize); if (newbuf == NULL) return (-1); memcpy(newbuf, s->s_buf, s->s_size); if (VSB_ISDYNAMIC(s)) SBFREE(s->s_buf); else VSB_SETFLAG(s, VSB_DYNAMIC); s->s_buf = newbuf; s->s_size = newsize; return (0); }