diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-08-05 11:51:25 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-08-05 11:51:25 +0000 |
commit | 17c382d1c9d7236c101418060758d2296cc5e17e (patch) | |
tree | fd00e58df0d9d3c70ddd1accfec9e819249c672a /src/config/confnode.c | |
download | tipidee-17c382d1c9d7236c101418060758d2296cc5e17e.tar.xz |
Initial commit
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/config/confnode.c')
-rw-r--r-- | src/config/confnode.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/config/confnode.c b/src/config/confnode.c new file mode 100644 index 0000000..758e79d --- /dev/null +++ b/src/config/confnode.c @@ -0,0 +1,35 @@ +/* ISC license. */ + +#include <stdint.h> +#include <string.h> + +#include <skalibs/stralloc.h> +#include <skalibs/strerr.h> + +#include "tipidee-config-internal.h" + +#define dienomem() strerr_diefu1sys(111, "stralloc_catb") +#define diestorage() strerr_diefu2x(100, "add node to configuration tree", ": too much data") +#define diefilepos() strerr_diefu2x(100, "add node to configuration tree", ": file too large") + +void confnode_start (confnode *node, char const *key, size_t filepos, uint32_t line) +{ + size_t l = strlen(key) ; + size_t k = g.storage.len ; + if (!stralloc_catb(&g.storage, key, l + 1)) dienomem() ; + if (g.storage.len >= UINT32_MAX) diestorage() ; + if (filepos > UINT32_MAX) diefilepos() ; + node->key = k ; + node->keylen = l ; + node->data = g.storage.len ; + node->datalen = 0 ; + node->filepos = filepos ; + node->line = line ; +} + +void confnode_add (confnode *node, char const *s, size_t len) +{ + if (!stralloc_catb(&g.storage, s, len)) dienomem() ; + if (g.storage.len >= UINT32_MAX) strerr_diefu1x(100, "add node to configuration tree: too much data") ; + node->datalen += len ; +} |