diff options
author | Mike Yuan <me@yhndnzj.com> | 2024-07-10 22:23:37 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2024-07-20 09:37:07 +0200 |
commit | 05c754bc7fe14e71721af6eb16194b9ad0690fb5 (patch) | |
tree | 4f21621dad7bc56fc7b6a4b376530375777a4151 /src/shared/exec-util.c | |
parent | zsh: update varlinkctl completions (diff) | |
download | systemd-05c754bc7fe14e71721af6eb16194b9ad0690fb5.tar.xz systemd-05c754bc7fe14e71721af6eb16194b9ad0690fb5.zip |
exec-util: modernize exec_command_flags_{to,from}_strv
- Rename ret params following our coding style
- Use assertion where appropriate
- Use BIT_FOREACH()
Diffstat (limited to 'src/shared/exec-util.c')
-rw-r--r-- | src/shared/exec-util.c | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/src/shared/exec-util.c b/src/shared/exec-util.c index 996edbf997..5408be5328 100644 --- a/src/shared/exec-util.c +++ b/src/shared/exec-util.c @@ -8,6 +8,7 @@ #include <stdio.h> #include "alloc-util.h" +#include "bitfield.h" #include "conf-files.h" #include "env-file.h" #include "env-util.h" @@ -425,46 +426,42 @@ static int gather_environment_consume(int fd, void *arg) { return r; } -int exec_command_flags_from_strv(char **ex_opts, ExecCommandFlags *flags) { - ExecCommandFlags ex_flag, ret_flags = 0; +int exec_command_flags_from_strv(char * const *ex_opts, ExecCommandFlags *ret) { + ExecCommandFlags flags = 0; - assert(flags); + assert(ret); STRV_FOREACH(opt, ex_opts) { - ex_flag = exec_command_flags_from_string(*opt); - if (ex_flag < 0) - return ex_flag; - ret_flags |= ex_flag; + ExecCommandFlags fl = exec_command_flags_from_string(*opt); + if (fl < 0) + return fl; + + flags |= fl; } - *flags = ret_flags; + *ret = flags; return 0; } -int exec_command_flags_to_strv(ExecCommandFlags flags, char ***ex_opts) { - _cleanup_strv_free_ char **ret_opts = NULL; - ExecCommandFlags it = flags; - const char *str; +int exec_command_flags_to_strv(ExecCommandFlags flags, char ***ret) { + _cleanup_strv_free_ char **opts = NULL; int r; - assert(ex_opts); - - if (flags < 0) - return flags; + assert(flags >= 0); + assert(ret); - for (unsigned i = 0; it != 0; it &= ~(1 << i), i++) - if (FLAGS_SET(flags, (1 << i))) { - str = exec_command_flags_to_string(1 << i); - if (!str) - return -EINVAL; + BIT_FOREACH(i, flags) { + const char *s = exec_command_flags_to_string(1 << i); + if (!s) + return -EINVAL; - r = strv_extend(&ret_opts, str); - if (r < 0) - return r; - } + r = strv_extend(&opts, s); + if (r < 0) + return r; + } - *ex_opts = TAKE_PTR(ret_opts); + *ret = TAKE_PTR(opts); return 0; } |