Home | History | Annotate | Download | only in shared

Lines Matching refs:buf

31 static bool buf_grow(struct strbuf *buf, size_t newsize)
36 if (newsize <= buf->size)
44 tmp = realloc(buf->bytes, sz);
47 buf->bytes = tmp;
48 buf->size = sz;
52 void strbuf_init(struct strbuf *buf)
54 buf->bytes = NULL;
55 buf->size = 0;
56 buf->used = 0;
59 void strbuf_release(struct strbuf *buf)
61 free(buf->bytes);
64 char *strbuf_steal(struct strbuf *buf)
68 bytes = realloc(buf->bytes, buf->used + 1);
70 free(buf->bytes);
73 bytes[buf->used] = '\0';
77 const char *strbuf_str(struct strbuf *buf)
79 if (!buf_grow(buf, buf->used + 1))
81 buf->bytes[buf->used] = '\0';
82 return buf->bytes;
85 bool strbuf_pushchar(struct strbuf *buf, char ch)
87 if (!buf_grow(buf, buf->used + 1))
89 buf->bytes[buf->used] = ch;
90 buf->used++;
94 unsigned strbuf_pushchars(struct strbuf *buf, const char *str)
99 assert(buf != NULL);
103 if (!buf_grow(buf, buf->used + len))
106 memcpy(buf->bytes + buf->used, str, len);
107 buf->used += len;
112 void strbuf_popchar(struct strbuf *buf)
114 assert(buf->used > 0);
115 buf->used--;
118 void strbuf_popchars(struct strbuf *buf, unsigned n)
120 assert(buf->used >= n);
121 buf->used -= n;
124 void strbuf_clear(struct strbuf *buf)
126 buf->used = 0;