diff options
author | Anton Kling <anton@kling.gg> | 2024-12-10 12:24:07 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-12-10 12:24:07 +0100 |
commit | 916aa42260290e9e864304bc7d9395b6aa693c27 (patch) | |
tree | 784cdcbe26e828e18413bf9d31d6a84ed74dd1ba /kernel/lib/sb.h | |
parent | bcca3d183930eeaf3d024476f39d1d8fccf2ebab (diff) |
kernel: Add string view and string builder
This makes write/read calls that use strings to communicate much
simpler and less error prone.
Diffstat (limited to 'kernel/lib/sb.h')
-rw-r--r-- | kernel/lib/sb.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/kernel/lib/sb.h b/kernel/lib/sb.h new file mode 100644 index 0000000..8493997 --- /dev/null +++ b/kernel/lib/sb.h @@ -0,0 +1,30 @@ +#ifndef SB_H +#define SB_H +#include "sv.h" +#include <stddef.h> +#include <stdint.h> + +struct sb { + char *string; + size_t length; + size_t capacity; + uint8_t prebuffer; +}; + +struct sv; + +void sb_init(struct sb *ctx); +int sb_init_capacity(struct sb *ctx, size_t starting_capacity); +void sb_init_buffer(struct sb *ctx, char *buffer, size_t size); +void sb_free(struct sb *ctx); +void sb_reset(struct sb *ctx); +int sb_isempty(const struct sb *ctx); +int sb_append_char(struct sb *ctx, char c); +int sb_delete_right(struct sb *ctx, size_t n); +int sb_append(struct sb *ctx, const char *s); +int sb_append_buffer(struct sb *ctx, const char *buffer, + size_t length); +int sb_append_sv(struct sb *ctx, struct sv sv); +int sb_prepend_sv(struct sb *ctx, struct sv sv); +int sb_prepend_buffer(struct sb *ctx, const char *buffer, size_t length); +#endif |