strv: declare iterator of FOREACH_STRING() in the loop

Same idea as 03677889f0.

No functional change intended. The type of the iterator is generally changed to
be 'const char*' instead of 'char*'. Despite the type commonly used, modifying
the string was not allowed.

I adjusted the naming of some short variables for clarity and reduced the scope
of some variable declarations in code that was being touched anyway.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2022-03-23 11:50:18 +01:00
parent 5b39139582
commit 5980d46304
53 changed files with 66 additions and 146 deletions
-1
View File
@@ -570,7 +570,6 @@ int get_files_in_directory(const char *path, char ***list) {
}
static int getenv_tmp_dir(const char **ret_path) {
const char *n;
int r, ret = 0;
assert(ret_path);
-2
View File
@@ -170,8 +170,6 @@ int open_extension_release(const char *root, const char *extension, char **ret_p
}
}
} else {
const char *p;
FOREACH_STRING(p, "/etc/os-release", "/usr/lib/os-release") {
r = chase_symlinks(p, root, CHASE_PREFIX_ROOT,
ret_path ? &q : NULL,
+1 -1
View File
@@ -218,7 +218,7 @@ void strv_print(char * const *l);
})
#define _FOREACH_STRING(uniq, x, y, ...) \
for (char **UNIQ_T(l, uniq) = STRV_MAKE(({ x = y; }), ##__VA_ARGS__); \
for (const char *x, * const*UNIQ_T(l, uniq) = STRV_MAKE_CONST(({ x = y; }), ##__VA_ARGS__); \
x; \
x = *(++UNIQ_T(l, uniq)))
-1
View File
@@ -236,7 +236,6 @@ bool lookup_paths_timestamp_hash_same(const LookupPaths *lp, uint64_t timestamp_
}
static int directory_name_is_valid(const char *name) {
const char *suffix;
/* Accept a directory whose name is a valid unit file name ending in .wants/, .requires/ or .d/ */