/* * Used as the default ->buf value, so that people can always assume * buf is non NULL and ->buf is NUL terminated even for a freshly * initialized strbuf.
*/ char strbuf_slopbuf[1];
int strbuf_grow(struct strbuf *sb, size_t extra)
{ char *buf;
size_t nr = sb->len + extra + 1;
if (nr < sb->alloc) return 0;
if (nr <= sb->len) return -E2BIG;
if (alloc_nr(sb->alloc) > nr)
nr = alloc_nr(sb->alloc);
/* * Note that sb->buf == strbuf_slopbuf if sb->alloc == 0, and it is * a static variable. Thus we have to avoid passing it to realloc.
*/
buf = realloc(sb->alloc ? sb->buf : NULL, nr * sizeof(*buf)); if (!buf) return -ENOMEM;
sb->buf = buf;
sb->alloc = nr; return 0;
}
int strbuf_addch(struct strbuf *sb, int c)
{ int ret = strbuf_grow(sb, 1); if (ret) return ret;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.