12#ifndef QPMS_CANONBUF_H
13#define QPMS_CANONBUF_H
35 if (b->len + extra + 1 <= b->cap)
return 0;
36 size_t ncap = b->cap ? b->cap : 4096;
37 while (b->len + extra + 1 > ncap) ncap *= 2;
38 char *nb = realloc(b->buf, ncap);
48 __attribute__((format(printf, 2, 3)))
57 const int need = vsnprintf(NULL, 0, fmt, ap);
59 if (need < 0 || qcb_reserve(b, (
size_t)need)) {
63 vsnprintf(b->buf + b->len, (
size_t)need + 1, fmt, ap2);
65 b->len += (size_t)need;
static int qpms_canonbuf_double(qpms_canonbuf_t *b, double v)
Appends a double with round-trip exactness (%.17g).
Definition canonbuf.h:70
static int qpms_canonbuf_cdouble(qpms_canonbuf_t *b, _Complex double v)
Appends a complex double as "(re,im)" with round-trip exact parts.
Definition canonbuf.h:75
static int qpms_canonbuf_printf(qpms_canonbuf_t *b, const char *fmt,...)
Appends a printf-formatted string; 0 on success, -1 on error.
Definition canonbuf.h:52
static int qpms_canonbuf_string(qpms_canonbuf_t *b, const char *s)
Appends a length-prefixed string (delimiter-safe; NULL and "" differ).
Definition canonbuf.h:81
static void qpms_canonbuf_free(qpms_canonbuf_t *b)
Frees the buffer contents (safe on a zero-initialised buffer).
Definition canonbuf.h:28