mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-22 22:03:43 +03:00
strv: introduce strv_copy_unless_empty()
(cherry picked from commit 5058bd7e1f0ae226d835253fcf333da3ab8d2806) (cherry picked from commit 24513d016b4278903240e192759d6d6bcc4954da) (cherry picked from commit e4763054c5434a89637d25053f0547e897e20cb4)
This commit is contained in:
parent
995722c3ef
commit
98d254fb35
@ -97,6 +97,22 @@ char** strv_copy(char * const *l) {
|
||||
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;
|
||||
|
||||
|
@ -30,6 +30,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(char**, strv_free_erase);
|
||||
#define _cleanup_strv_free_erase_ _cleanup_(strv_free_erasep)
|
||||
|
||||
char** strv_copy(char * const *l);
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user