diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:03:56 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:03:56 +0000 |
commit | 18da3ffcd7f3c8a0c5f790c801b5813503c2273d (patch) | |
tree | 84caf98dc5cef3d123c56ba12e35fd67026e0693 /shared/strbuf.h | |
parent | Initial commit. (diff) | |
download | kmod-18da3ffcd7f3c8a0c5f790c801b5813503c2273d.tar.xz kmod-18da3ffcd7f3c8a0c5f790c801b5813503c2273d.zip |
Adding upstream version 31+20240202.upstream/31+20240202
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'shared/strbuf.h')
-rw-r--r-- | shared/strbuf.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/shared/strbuf.h b/shared/strbuf.h new file mode 100644 index 0000000..0f7ceb1 --- /dev/null +++ b/shared/strbuf.h @@ -0,0 +1,30 @@ +#pragma once + +#include <stdbool.h> + +/* + * Buffer abstract data type + */ +struct strbuf { + char *bytes; + unsigned size; + unsigned used; +}; + +void strbuf_init(struct strbuf *buf); +void strbuf_release(struct strbuf *buf); +void strbuf_clear(struct strbuf *buf); + +/* Destroy buffer and return a copy as a C string */ +char *strbuf_steal(struct strbuf *buf); + +/* + * Return a C string owned by the buffer invalidated if the buffer is + * changed). + */ +const char *strbuf_str(struct strbuf *buf); + +bool strbuf_pushchar(struct strbuf *buf, char ch); +unsigned strbuf_pushchars(struct strbuf *buf, const char *str); +void strbuf_popchar(struct strbuf *buf); +void strbuf_popchars(struct strbuf *buf, unsigned n); |