strbuf: make length for strbuf_add_string() optional

This commit is contained in:
Yu Watanabe
2024-06-12 03:25:57 +09:00
parent 34d4e6f32a
commit 3bc70f104e
5 changed files with 22 additions and 20 deletions

View File

@@ -105,13 +105,16 @@ static void bubbleinsert(struct strbuf_node *node,
}
/* add string, return the index/offset into the buffer */
ssize_t strbuf_add_string(struct strbuf *str, const char *s, size_t len) {
ssize_t strbuf_add_string_full(struct strbuf *str, const char *s, size_t len) {
uint8_t c;
ssize_t off;
assert(str);
assert(s || len == 0);
if (len == SIZE_MAX)
len = strlen(s);
if (!str->root)
return -EINVAL;

View File

@@ -33,7 +33,10 @@ struct strbuf_child_entry {
};
struct strbuf* strbuf_new(void);
ssize_t strbuf_add_string(struct strbuf *str, const char *s, size_t len);
ssize_t strbuf_add_string_full(struct strbuf *str, const char *s, size_t len);
static inline ssize_t strbuf_add_string(struct strbuf *str, const char *s) {
return strbuf_add_string_full(str, s, SIZE_MAX);
}
void strbuf_complete(struct strbuf *str);
struct strbuf* strbuf_free(struct strbuf *str);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct strbuf*, strbuf_free);