added mbuf_fill()

This commit is contained in:
Richard Aas 2013-04-29 10:43:38 +00:00
parent af6e8c9c27
commit 9c5dd83781
2 changed files with 38 additions and 0 deletions

View file

@ -64,6 +64,7 @@ int mbuf_vprintf(struct mbuf *mb, const char *fmt, va_list ap);
int mbuf_printf(struct mbuf *mb, const char *fmt, ...);
int mbuf_write_pl_skip(struct mbuf *mb, const struct pl *pl,
const struct pl *skip);
int mbuf_fill(struct mbuf *mb, uint8_t c, size_t n);
int mbuf_debug(struct re_printf *pf, const struct mbuf *mb);

View file

@ -511,6 +511,43 @@ int mbuf_write_pl_skip(struct mbuf *mb, const struct pl *pl,
}
/**
* Write n bytes of value 'c' to a memory buffer
*
* @param mb Memory buffer
* @param c Value to write
* @param n Number of bytes to write
*
* @return 0 if success, otherwise errorcode
*/
int mbuf_fill(struct mbuf *mb, uint8_t c, size_t n)
{
size_t rsize;
if (!mb || !n)
return EINVAL;
rsize = mb->pos + n;
if (rsize > mb->size) {
const size_t dsize = mb->size ? (mb->size * 2)
: DEFAULT_SIZE;
int err;
err = mbuf_resize(mb, MAX(rsize, dsize));
if (err)
return err;
}
memset(mb->buf + mb->pos, c, n);
mb->pos += n;
mb->end = MAX(mb->end, mb->pos);
return 0;
}
/**
* Debug the memory buffer
*