udebug: add functions for manipulating entry length
Can be used to reserve worst case length using udebug_entry_append, then setting the final length using udebug_entry_set_length Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
parent
e80dc00ee9
commit
325fea5c57
2 changed files with 21 additions and 0 deletions
19
udebug.c
19
udebug.c
|
@ -467,6 +467,25 @@ void *udebug_entry_append(struct udebug_buf *buf, const void *data, uint32_t len
|
|||
return ret;
|
||||
}
|
||||
|
||||
uint16_t udebug_entry_trim(struct udebug_buf *buf, uint16_t len)
|
||||
{
|
||||
struct udebug_hdr *hdr = buf->hdr;
|
||||
struct udebug_ptr *ptr = udebug_ring_ptr(hdr, hdr->head);
|
||||
|
||||
if (len)
|
||||
ptr->len -= len;
|
||||
|
||||
return ptr->len;
|
||||
}
|
||||
|
||||
void udebug_entry_set_length(struct udebug_buf *buf, uint16_t len)
|
||||
{
|
||||
struct udebug_hdr *hdr = buf->hdr;
|
||||
struct udebug_ptr *ptr = udebug_ring_ptr(hdr, hdr->head);
|
||||
|
||||
ptr->len = len;
|
||||
}
|
||||
|
||||
int udebug_entry_printf(struct udebug_buf *buf, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
|
2
udebug.h
2
udebug.h
|
@ -157,6 +157,8 @@ int udebug_entry_printf(struct udebug_buf *buf, const char *fmt, ...)
|
|||
__attribute__ ((format (printf, 2, 3)));
|
||||
int udebug_entry_vprintf(struct udebug_buf *buf, const char *fmt, va_list ap)
|
||||
__attribute__ ((format (printf, 2, 0)));
|
||||
uint16_t udebug_entry_trim(struct udebug_buf *buf, uint16_t len);
|
||||
void udebug_entry_set_length(struct udebug_buf *buf, uint16_t len);
|
||||
void udebug_entry_add(struct udebug_buf *buf);
|
||||
|
||||
int udebug_buf_init(struct udebug_buf *buf, size_t entries, size_t size);
|
||||
|
|
Loading…
Reference in a new issue