Fallback to unbuffered printing if OOM

This commit is contained in:
Yinan Zhang
2020-01-13 14:23:10 -08:00
parent cd6e908241
commit f81341a48b
4 changed files with 39 additions and 21 deletions

View File

@@ -23,7 +23,9 @@ buf_write_init(buf_write_arg_t *arg, void (*write_cb)(void *, const char *),
void *cbopaque, char *buf, size_t buf_len) {
arg->write_cb = write_cb;
arg->cbopaque = cbopaque;
assert(buf != NULL);
arg->buf = buf;
assert(buf_len >= 2);
arg->buf_size = buf_len - 1; /* Accommodating '\0' at the end. */
arg->buf_end = 0;
}