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/libtipidee/tipidee_conf_get_argv.c | |
| download | tipidee-17c382d1c9d7236c101418060758d2296cc5e17e.tar.gz | |
Initial commit
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libtipidee/tipidee_conf_get_argv.c')
| -rw-r--r-- | src/libtipidee/tipidee_conf_get_argv.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/libtipidee/tipidee_conf_get_argv.c b/src/libtipidee/tipidee_conf_get_argv.c new file mode 100644 index 0000000..0dd016e --- /dev/null +++ b/src/libtipidee/tipidee_conf_get_argv.c @@ -0,0 +1,32 @@ +/* ISC license. */ + +#include <errno.h> +#include <string.h> + +#include <skalibs/cdb.h> + +#include <tipidee/conf.h> + +#include <skalibs/posixishard.h> + +unsigned int tipidee_conf_get_argv (tipidee_conf const *conf, char const *key, char const **argv, unsigned int max, size_t *maxlen) +{ + cdb_data data ; + size_t curlen = 0 ; + unsigned int n = 0, pos = 0 ; + if (!tipidee_conf_get(conf, key, &data)) return 0 ; + if (data.s[data.len-1]) return (errno = EPROTO, 0) ; + while (pos < data.len) + { + size_t len ; + if (n >= max) return (errno = E2BIG, 0) ; + argv[n++] = data.s + pos ; + len = strlen(data.s + pos) ; + if (len > curlen) curlen = len ; + pos += len + 1 ; + } + if (n >= max) return (errno = E2BIG, 0) ; + argv[n++] = 0 ; + if (maxlen) *maxlen = curlen ; + return n ; +} |
