From 824a4b3da2c0be19ccf54a48dcd4c10677b82c1a Mon Sep 17 00:00:00 2001 From: Gabor Juhos Date: Tue, 10 Sep 2013 12:59:25 +0200 Subject: [PATCH] udevtrigger: reduce indent level in scan_* functions Return early from the scan_* functions if the opendir call fails. This allows to reduce the indentation level of the subsequent code by one tab. Signed-off-by: Gabor Juhos --- udevtrigger.c | 103 ++++++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 49 deletions(-) diff --git a/udevtrigger.c b/udevtrigger.c index 98b0743..dbb414a 100644 --- a/udevtrigger.c +++ b/udevtrigger.c @@ -185,20 +185,19 @@ static void scan_subdir(const char *base) struct dirent *dent; dir = opendir(base); - if (dir != NULL) { - for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { - char dirname[PATH_SIZE]; + if (dir == NULL) + return; - if (dent->d_name[0] == '.') - continue; + for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { + char dirname[PATH_SIZE]; - strlcpy(dirname, base, sizeof(dirname)); - strlcat(dirname, "/", sizeof(dirname)); - strlcat(dirname, dent->d_name, sizeof(dirname)); - device_list_insert(dirname); - } - closedir(dir); + strlcpy(dirname, base, sizeof(dirname)); + strlcat(dirname, "/", sizeof(dirname)); + strlcat(dirname, dent->d_name, sizeof(dirname)); + device_list_insert(dirname); } + + closedir(dir); } static void scan_subsystem(const char *subsys) @@ -211,23 +210,25 @@ static void scan_subsystem(const char *subsys) strlcat(base, subsys, sizeof(base)); dir = opendir(base); - if (dir != NULL) { - for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { - char dirname[PATH_SIZE]; + if (dir == NULL) + return; - if (dent->d_name[0] == '.') - continue; + for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { + char dirname[PATH_SIZE]; - strlcpy(dirname, base, sizeof(dirname)); - strlcat(dirname, "/", sizeof(dirname)); - strlcat(dirname, dent->d_name, sizeof(dirname)); - strlcat(dirname, "/devices", sizeof(dirname)); + if (dent->d_name[0] == '.') + continue; - /* look for devices */ - scan_subdir(dirname); - } - closedir(dir); + strlcpy(dirname, base, sizeof(dirname)); + strlcat(dirname, "/", sizeof(dirname)); + strlcat(dirname, dent->d_name, sizeof(dirname)); + strlcat(dirname, "/devices", sizeof(dirname)); + + /* look for devices */ + scan_subdir(dirname); } + + closedir(dir); } static void scan_block(void) @@ -239,24 +240,26 @@ static void scan_block(void) strlcpy(base, "/sys/block", sizeof(base)); dir = opendir(base); - if (dir != NULL) { - for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { - char dirname[PATH_SIZE]; + if (dir == NULL) + return; - if (dent->d_name[0] == '.') - continue; + for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { + char dirname[PATH_SIZE]; - strlcpy(dirname, base, sizeof(dirname)); - strlcat(dirname, "/", sizeof(dirname)); - strlcat(dirname, dent->d_name, sizeof(dirname)); - if (device_list_insert(dirname) != 0) - continue; + if (dent->d_name[0] == '.') + continue; - /* look for partitions */ - scan_subdir(dirname); - } - closedir(dir); + strlcpy(dirname, base, sizeof(dirname)); + strlcat(dirname, "/", sizeof(dirname)); + strlcat(dirname, dent->d_name, sizeof(dirname)); + if (device_list_insert(dirname) != 0) + continue; + + /* look for partitions */ + scan_subdir(dirname); } + + closedir(dir); } static void scan_class(void) @@ -268,21 +271,23 @@ static void scan_class(void) strlcpy(base, "/sys/class", sizeof(base)); dir = opendir(base); - if (dir != NULL) { - for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { - char dirname[PATH_SIZE]; + if (dir == NULL) + return; - if (dent->d_name[0] == '.') - continue; + for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { + char dirname[PATH_SIZE]; - strlcpy(dirname, base, sizeof(dirname)); - strlcat(dirname, "/", sizeof(dirname)); - strlcat(dirname, dent->d_name, sizeof(dirname)); + if (dent->d_name[0] == '.') + continue; - scan_subdir(dirname); - } - closedir(dir); + strlcpy(dirname, base, sizeof(dirname)); + strlcat(dirname, "/", sizeof(dirname)); + strlcat(dirname, dent->d_name, sizeof(dirname)); + + scan_subdir(dirname); } + + closedir(dir); } int main(int argc, char *argv[], char *envp[]) -- 2.25.1