]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/strbuf.h
man/systemd-sysext: list ephemeral/ephemeral-import in the list of options
[thirdparty/systemd.git] / src / basic / strbuf.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "forward.h"
5
6 struct strbuf {
7 char *buf;
8 size_t len;
9 struct strbuf_node *root;
10
11 size_t nodes_count;
12 size_t in_count;
13 size_t in_len;
14 size_t dedup_len;
15 size_t dedup_count;
16 };
17
18 struct strbuf_node {
19 size_t value_off;
20 size_t value_len;
21
22 struct strbuf_child_entry *children;
23 uint8_t children_count;
24 };
25
26 struct strbuf_child_entry {
27 uint8_t c;
28 struct strbuf_node *child;
29 };
30
31 struct strbuf* strbuf_new(void);
32 ssize_t strbuf_add_string_full(struct strbuf *str, const char *s, size_t len);
33 static inline ssize_t strbuf_add_string(struct strbuf *str, const char *s) {
34 return strbuf_add_string_full(str, s, SIZE_MAX);
35 }
36 void strbuf_complete(struct strbuf *str);
37 struct strbuf* strbuf_free(struct strbuf *str);
38 DEFINE_TRIVIAL_CLEANUP_FUNC(struct strbuf*, strbuf_free);