From 3c5db5339454f48edb48c9b1498c1832c6711eb1 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 26 Jun 2023 17:19:35 -0700 Subject: til_str: exclude \0 from res_len for til_str_buf()/til_str_to_buf() It's more ergonomic more often to behave consistently with strlen() here, plus it's just the established mental model. While here I made til_settings_path_as_buf() private as nothing external uses it, it's essentially just a logically distinct private helper function from the public wrappers around it. Dragged into this changeset due to clarifying some naming/semantics as it's one of the few til_str_to_buf() callers. But nobody was actually passing a non-NULL res_bufsz/res_len to it anyways, as its use is minimal. --- src/til_settings.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/til_settings.c') diff --git a/src/til_settings.c b/src/til_settings.c index 2985635..fb71bf7 100644 --- a/src/til_settings.c +++ b/src/til_settings.c @@ -679,7 +679,11 @@ int til_settings_strprint_path(const til_settings_t *settings, til_str_t *str) } -int til_settings_path_as_buf(const til_settings_t *settings, char **res_buf, size_t *res_bufsz) +/* + * returns a raw path to settings in *res_buf + * if res_len is provided, the returned string length excluding nul is stored there (til_str_to_buf()) + */ +static int til_settings_path_as_buf(const til_settings_t *settings, char **res_buf, size_t *res_len) { til_str_t *str; int r; @@ -695,7 +699,7 @@ int til_settings_path_as_buf(const til_settings_t *settings, char **res_buf, siz if (r < 0) return r; - *res_buf = til_str_to_buf(str, res_bufsz); + *res_buf = til_str_to_buf(str, res_len); return 0; } -- cgit v1.2.1