From c7f0d9e5acef3f62db3640d5ab7446241c022b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 7 Dec 2021 15:02:55 +0100 Subject: 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. --- src/import/import-common.c | 12 ++++++------ src/import/pull-common.c | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/import') diff --git a/src/import/import-common.c b/src/import/import-common.c index c36105221f..4eda9087c5 100644 --- a/src/import/import-common.c +++ b/src/import/import-common.c @@ -159,7 +159,7 @@ int import_fork_tar_c(const char *path, pid_t *ret) { int import_mangle_os_tree(const char *path) { _cleanup_free_ char *child = NULL, *t = NULL, *joined = NULL; _cleanup_closedir_ DIR *d = NULL, *cd = NULL; - struct dirent *de; + struct dirent *dent; struct stat st; int r; @@ -183,8 +183,8 @@ int import_mangle_os_tree(const char *path) { return log_error_errno(r, "Failed to open directory '%s': %m", path); errno = 0; - de = readdir_no_dot(d); - if (!de) { + dent = readdir_no_dot(d); + if (!dent) { if (errno != 0) return log_error_errno(errno, "Failed to iterate through directory '%s': %m", path); @@ -192,13 +192,13 @@ int import_mangle_os_tree(const char *path) { return 0; } - child = strdup(de->d_name); + child = strdup(dent->d_name); if (!child) return log_oom(); errno = 0; - de = readdir_no_dot(d); - if (de) { + dent = readdir_no_dot(d); + if (dent) { if (errno != 0) return log_error_errno(errno, "Failed to iterate through directory '%s': %m", path); diff --git a/src/import/pull-common.c b/src/import/pull-common.c index d0d0c85adc..028bae82a8 100644 --- a/src/import/pull-common.c +++ b/src/import/pull-common.c @@ -59,7 +59,6 @@ int pull_find_old_etags( } _cleanup_strv_free_ char **ans = NULL; - struct dirent *de; FOREACH_DIRENT_ALL(de, d, return -errno) { _cleanup_free_ char *u = NULL; -- cgit v1.2.1