Use mg_putchar_iobuf in mg_vprintf

This commit is contained in:
Sergey Lyubka committed 2022-06-29 17:42:55 +01:00
1 parent 017c7290d6
commit 73297c8e65
6 files changed
+36 -16

No files matched your search

+13 -2
View File
@@ -47,7 +47,6 @@ char *mg_mprintf(const char *fmt, ...) {
return s;
}
size_t mg_rprintf(void (*out)(char, void *), void *ptr, const char *fmt, ...) {
size_t len = 0;
va_list ap;
@@ -59,7 +58,19 @@ size_t mg_rprintf(void (*out)(char, void *), void *ptr, const char *fmt, ...) {
static void mg_putchar_iobuf_static(char ch, void *param) {
struct mg_iobuf *io = (struct mg_iobuf *) param;
if (io->len < io->size) io->buf[io->len++] = (uint8_t) ch;
if (io->len + 2 <= io->size) {
io->buf[io->len++] = (uint8_t) ch;
io->buf[io->len] = 0;
}
}
static void mg_putchar_iobuf(char ch, void *param) {
struct mg_iobuf *io = (struct mg_iobuf *) param;
if (io->len + 2 > io->size) mg_iobuf_resize(io, io->size + 64);
if (io->len + 2 <= io->size) {
io->buf[io->len++] = (uint8_t) ch;
io->buf[io->len] = 0;
}
}
// We don't use realloc() in mongoose, so resort to inefficient calloc