tree-wide: make FOREACH_DIRENT_ALL define the iterator variable
The variable is not useful outside of the loop (it'll always be null after the loop is finished), so we can declare it inline in the loop. This saves one variable declaration and reduces the chances that somebody tries to use the variable outside of the loop. For consistency, 'de' is used everywhere for the var name.
This commit is contained in:
@@ -199,8 +199,6 @@ int cg_enumerate_subgroups(const char *controller, const char *path, DIR **_d) {
|
||||
}
|
||||
|
||||
int cg_read_subgroup(DIR *d, char **fn) {
|
||||
struct dirent *de;
|
||||
|
||||
assert(d);
|
||||
assert(fn);
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ struct dirent *readdir_no_dot(DIR *dirp);
|
||||
else
|
||||
|
||||
#define FOREACH_DIRENT_ALL(de, d, on_error) \
|
||||
for (de = readdir_ensure_type(d);; de = readdir_ensure_type(d)) \
|
||||
for (struct dirent *(de) = readdir_ensure_type(d);; (de) = readdir_ensure_type(d)) \
|
||||
if (!de) { \
|
||||
if (errno > 0) { \
|
||||
on_error; \
|
||||
|
||||
@@ -533,7 +533,6 @@ int mkfifoat_atomic(int dirfd, const char *path, mode_t mode) {
|
||||
int get_files_in_directory(const char *path, char ***list) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
_cleanup_closedir_ DIR *d = NULL;
|
||||
struct dirent *de;
|
||||
size_t n = 0;
|
||||
|
||||
assert(path);
|
||||
|
||||
@@ -276,7 +276,6 @@ int unit_file_build_name_map(
|
||||
|
||||
STRV_FOREACH(dir, (char**) lp->search_path) {
|
||||
_cleanup_closedir_ DIR *d = NULL;
|
||||
struct dirent *de;
|
||||
|
||||
d = opendir(*dir);
|
||||
if (!d) {
|
||||
|
||||
Reference in New Issue
Block a user