strv: introduce strv_copy_unless_empty()
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user