summaryrefslogtreecommitdiff
path: root/src/basic/strv.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-03-16 22:29:32 +0900
committerLennart Poettering <lennart@poettering.net>2022-03-18 18:36:48 +0100
commit9eb814818d0c35f0c9e05cb596508c1536b0e654 (patch)
treecbb8d312ab88c5f81d191cf5db69510b7e6d93f3 /src/basic/strv.c
parent52bb308c138dd1006078370c93e0e77dfc61de73 (diff)
downloadsystemd-9eb814818d0c35f0c9e05cb596508c1536b0e654.tar.gz
strv: rewrite strv_copy() with cleanup attribute and STRV_FOREACH()
Diffstat (limited to 'src/basic/strv.c')
-rw-r--r--src/basic/strv.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/basic/strv.c b/src/basic/strv.c
index cf573a3783..07a6c49b50 100644
--- a/src/basic/strv.c
+++ b/src/basic/strv.c
@@ -89,23 +89,23 @@ char** strv_free_erase(char **l) {
}
char** strv_copy(char * const *l) {
- char **r, **k;
+ _cleanup_strv_free_ char **result = NULL;
+ char **k, * const *i;
- k = r = new(char*, strv_length(l) + 1);
- if (!r)
+ result = new(char*, strv_length(l) + 1);
+ if (!result)
return NULL;
- if (l)
- for (; *l; k++, l++) {
- *k = strdup(*l);
- if (!*k) {
- strv_free(r);
- return NULL;
- }
- }
+ k = result;
+ STRV_FOREACH(i, l) {
+ *k = strdup(*i);
+ if (!*k)
+ return NULL;
+ k++;
+ }
*k = NULL;
- return r;
+ return TAKE_PTR(result);
}
size_t strv_length(char * const *l) {