From 735790f1b14e09e43ebd0e0dccd1124d5fd4e78b Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 4 May 2026 19:42:25 -0400 Subject: Change strlist tokenizer return types from void to int --- src/lib/core/include/strlist.h | 6 +++-- src/lib/core/strlist.c | 59 +++++++++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/lib/core/include/strlist.h b/src/lib/core/include/strlist.h index b2d7da7..f44025c 100644 --- a/src/lib/core/include/strlist.h +++ b/src/lib/core/include/strlist.h @@ -45,8 +45,10 @@ int strlist_append_file(struct StrList *pStrList, char *path, ReaderFn *readerFn void strlist_append_strlist(struct StrList *pStrList1, struct StrList *pStrList2); void strlist_append(struct StrList **pStrList, char *str); void strlist_append_array(struct StrList *pStrList, char **arr); -void strlist_append_tokenize(struct StrList *pStrList, char *str, char *delim); -void strlist_append_tokenize_raw(struct StrList *pStrList, char *str, char *delim); + +int strlist_append_tokenize(struct StrList *pStrList, char *str, char *delim); + +int strlist_append_tokenize_raw(struct StrList *pStrList, char *str, char *delim); int strlist_appendf(struct StrList **pStrList, const char *fmt, ...); struct StrList *strlist_copy(struct StrList *pStrList); int strlist_cmp(struct StrList *a, struct StrList *b); diff --git a/src/lib/core/strlist.c b/src/lib/core/strlist.c index 42d5b85..0d25a66 100644 --- a/src/lib/core/strlist.c +++ b/src/lib/core/strlist.c @@ -218,22 +218,30 @@ void strlist_append_strlist(struct StrList *pStrList1, struct StrList *pStrList2 * @param str * @param delim */ - void strlist_append_tokenize(struct StrList *pStrList, char *str, char *delim) { - if (!str || !delim) { - return; - } +int strlist_append_tokenize(struct StrList *pStrList, char *str, char *delim) { + if (!str || !delim) { + return -1; + } - char *tmp = strdup(str); - char **token = split(tmp, delim, 0); - if (token) { - for (size_t i = 0; token[i] != NULL; i++) { - lstrip(token[i]); - strlist_append(&pStrList, token[i]); - } - guard_array_free(token); - } + char *tmp = strdup(str); + if (!tmp) { + return -1; + } + + char **token = split(tmp, delim, 0); + if (!token) { + guard_free(tmp); + return -1; + } + for (size_t i = 0; token[i] != NULL; i++) { + lstrip(token[i]); + strlist_append(&pStrList, token[i]); + } + guard_array_free(token); guard_free(tmp); - } + + return 0; +} /** * Append the contents of a newline delimited string without @@ -242,20 +250,29 @@ void strlist_append_strlist(struct StrList *pStrList1, struct StrList *pStrList2 * @param str * @param delim */ -void strlist_append_tokenize_raw(struct StrList *pStrList, char *str, char *delim) { +int strlist_append_tokenize_raw(struct StrList *pStrList, char *str, char *delim) { if (!str || !delim) { - return; + return -1; } char *tmp = strdup(str); + if (!tmp) { + return -1; + } + char **token = split(tmp, delim, 0); - if (token) { - for (size_t i = 0; token[i] != NULL; i++) { - strlist_append(&pStrList, token[i]); - } - guard_array_free(token); + if (!token) { + guard_free(tmp); + return -1; } + + for (size_t i = 0; token[i] != NULL; i++) { + strlist_append(&pStrList, token[i]); + } + + guard_array_free(token); guard_free(tmp); + return 0; } /** -- cgit