From 68f6dee32dea0fb1bfe40d901169cf68aa6528d0 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 3 Jul 2023 07:54:21 -0700 Subject: til_settings: add til_setting_desc_strprint_path() variant There was only til_setting_desc_fprint_path() (for setup_interactively()), but for rkt_scener this stuff has to go out the socket and the queueing mechanism is built around til_str_t so let's get a til_str_t-centric variant in there. --- src/til_settings.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'src/til_settings.c') diff --git a/src/til_settings.c b/src/til_settings.c index c546360..46224ef 100644 --- a/src/til_settings.c +++ b/src/til_settings.c @@ -475,23 +475,17 @@ til_setting_desc_t * til_setting_desc_free(const til_setting_desc_t *desc) } -int til_setting_desc_fprint_path(const til_setting_desc_t *desc, FILE *out) + +int til_setting_desc_strprint_path(const til_setting_desc_t *desc, til_str_t *str) { - til_str_t *str; - int r; + int r; assert(desc); - assert(out); - - str = til_str_new(""); - if (!str) - return -ENOMEM; + assert(str); r = til_settings_strprint_path(desc->container, str); - if (r < 0) { - til_str_free(str); + if (r < 0) return r; - } /* XXX: spec.as_label handling is done in til_settings_print_path() since it * must apply anywhere within a path, potentially in a recurring fashion. @@ -504,10 +498,30 @@ int til_setting_desc_fprint_path(const til_setting_desc_t *desc, FILE *out) */ if (desc->spec.key) { r = til_str_appendf(str, "/%s", desc->spec.key); - if (r < 0) { - til_str_free(str); + if (r < 0) return r; - } + } + + return 0; +} + + +int til_setting_desc_fprint_path(const til_setting_desc_t *desc, FILE *out) +{ + til_str_t *str; + int r; + + assert(desc); + assert(out); + + str = til_str_new(""); + if (!str) + return -ENOMEM; + + r = til_setting_desc_strprint_path(desc, str); + if (r < 0) { + til_str_free(str); + return r; } if (fputs(til_str_buf(str, NULL), out) == EOF) -- cgit v1.2.1