lib: add bputs/bputch fbuf (bprintfrr) helpers

Just small utilities for when you already have a struct fbuf (i.e. when
bprintfrr() is used to construct longer text from multiple pieces.)

Signed-off-by: David Lamparter <equinox@diac24.net>
This commit is contained in:
David Lamparter 2021-03-15 21:39:11 +01:00
parent 992c42ef01
commit e6b3732e90

View file

@ -160,6 +160,30 @@ void printfrr_ext_reg(const struct printfrr_ext *);
} \ } \
/* end */ /* end */
/* fbuf helper functions */
static inline ssize_t bputs(struct fbuf *buf, const char *str)
{
size_t len = strlen(str);
size_t ncopy;
if (!buf)
return len;
ncopy = MIN(len, (size_t)(buf->buf + buf->len - buf->pos));
memcpy(buf->pos, str, ncopy);
buf->pos += ncopy;
return len;
}
static inline ssize_t bputch(struct fbuf *buf, char ch)
{
if (buf && buf->pos < buf->buf + buf->len)
*buf->pos++ = ch;
return 1;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif