tokenizing hello.zig

This commit is contained in:
Andrew Kelley
2015-11-01 22:21:33 -07:00
parent 5f48463bdd
commit 34f8d80eac
6 changed files with 182 additions and 178 deletions

View File

@@ -23,3 +23,24 @@ Buf *buf_sprintf(const char *format, ...) {
return buf;
}
void buf_appendf(Buf *buf, const char *format, ...) {
va_list ap, ap2;
va_start(ap, format);
va_copy(ap2, ap);
int len1 = vsnprintf(nullptr, 0, format, ap);
assert(len1 >= 0);
size_t required_size = len1 + 1;
int orig_len = buf_len(buf);
buf_resize(buf, orig_len + required_size);
int len2 = vsnprintf(buf_ptr(buf) + orig_len, required_size, format, ap2);
assert(len2 == len1);
va_end(ap2);
va_end(ap);
}