Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2023-11-29 17:38:30 +0300
committerFelix Fietkau <nbd@nbd.name>2023-11-29 23:59:23 +0300
commit325fea5c57cf7917ff5e633dd28715af84018993 (patch)
tree2794c2174eb7fc54e795a5eed1a1017e5e2d35b9
parente80dc00ee90c29ef56ae28f414b0e5bb361206e7 (diff)
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>
-rw-r--r--udebug.c19
-rw-r--r--udebug.h2
2 files changed, 21 insertions, 0 deletions
diff --git a/udebug.c b/udebug.c
index 5be9b54..00a66ab 100644
--- a/udebug.c
+++ b/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;
diff --git a/udebug.h b/udebug.h
index d24dbfc..75c2e3f 100644
--- a/udebug.h
+++ b/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);