strv: introduce strv_copy_unless_empty()

This commit is contained in:
Ludwig Nussel
2024-01-15 17:16:37 +01:00
parent 01526fedef
commit 5058bd7e1f
2 changed files with 18 additions and 0 deletions
+16
View File
@@ -123,6 +123,22 @@ char** strv_copy_n(char * const *l, size_t m) {
return TAKE_PTR(result);
}
int strv_copy_unless_empty(char * const *l, char ***ret) {
assert(ret);
if (strv_isempty(l)) {
*ret = NULL;
return 0;
}
char **copy = strv_copy(l);
if (!copy)
return -ENOMEM;
*ret = TAKE_PTR(copy);
return 1;
}
size_t strv_length(char * const *l) {
size_t n = 0;
+2
View File
@@ -38,6 +38,8 @@ char** strv_copy_n(char * const *l, size_t n);
static inline char** strv_copy(char * const *l) {
return strv_copy_n(l, SIZE_MAX);
}
int strv_copy_unless_empty(char * const *l, char ***ret);
size_t strv_length(char * const *l) _pure_;
int strv_extend_strv(char ***a, char * const *b, bool filter_duplicates);