]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
treewide: use is_dotdir_dirent() helper
authorKarel Zak <kzak@redhat.com>
Wed, 15 Oct 2025 13:46:06 +0000 (15:46 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 15 Oct 2025 13:46:06 +0000 (15:46 +0200)
This simplifies the code by using the is_dotdir_dirent() helper
function instead of manual strcmp() checks for "." and ".." directory
entries across multiple utilities.

Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/partx.c
lib/loopdev.c
libsmartcols/samples/tree.c
misc-utils/whereis.c
sys-utils/eject.c
sys-utils/switch_root.c

index 347d5daad303d688f2da4d6778f5175689c4f56a..68d29f62f414ebd90603635276d0e7997b860f7f 100644 (file)
@@ -41,6 +41,7 @@
 #include "loopdev.h"
 #include "closestream.h"
 #include "optutils.h"
+#include "fileutils.h"
 
 /* this is the default upper limit, could be modified by --nr */
 #define SLICES_MAX     256
@@ -245,8 +246,7 @@ static int get_max_partno(const char *disk, dev_t devno)
        while ((d = readdir(dir))) {
                int fd;
 
-               if (!strcmp(d->d_name, ".") ||
-                   !strcmp(d->d_name, ".."))
+               if (is_dotdir_dirent(d))
                        continue;
 #ifdef _DIRENT_HAVE_D_TYPE
                if (d->d_type != DT_DIR && d->d_type != DT_UNKNOWN)
index a32003d4b0ebc00bb7c18f32148a436ea8815c4c..5ef4394407958a7501f7f4fe58293563a92e7b33 100644 (file)
@@ -478,7 +478,7 @@ static int loop_scandir(const char *dirname, int **ary, int hasprefix)
                    d->d_type != DT_LNK)
                        continue;
 #endif
-               if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
+               if (is_dotdir_dirent(d))
                        continue;
 
                if (hasprefix) {
@@ -584,9 +584,7 @@ static int loopcxt_next_from_sysfs(struct loopdev_cxt *lc)
 
                DBG(ITER, ul_debugobj(iter, "check %s", d->d_name));
 
-               if (strcmp(d->d_name, ".") == 0
-                   || strcmp(d->d_name, "..") == 0
-                   || strncmp(d->d_name, "loop", 4) != 0)
+               if (is_dotdir_dirent(d) || strncmp(d->d_name, "loop", 4) != 0)
                        continue;
 
                snprintf(name, sizeof(name), "%s/loop/backing_file", d->d_name);
index e40ea9a313cb62af7350268d3a9e819a64f90e35..bdb93629a2db3d60a45124f0b42638be7163bfd5 100644 (file)
@@ -16,6 +16,7 @@
 #include "c.h"
 #include "nls.h"
 #include "strutils.h"
+#include "fileutils.h"
 
 #include "libsmartcols.h"
 
@@ -124,7 +125,7 @@ static int add_children(struct libscols_table *tb,
        while ((d = readdir(dir))) {
                struct stat st;
 
-               if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0)
+               if (is_dotdir_dirent(d))
                        continue;
                if (fstatat(fd, d->d_name, &st, AT_SYMLINK_NOFOLLOW) != 0)
                        continue;
index 8e500c00983487d4e532c056eb8505a1f3479063..f705ac278ef6b5c3c3002b06f2230da0b5078e8b 100644 (file)
@@ -57,6 +57,7 @@
 #include "c.h"
 #include "closestream.h"
 #include "canonicalize.h"
+#include "fileutils.h"
 
 #include "debug.h"
 
@@ -297,7 +298,7 @@ static void dirlist_add_subdir(struct wh_dirlist **ls, int type, const char *dir
                                dir, buf, postfix ? postfix : ""));
 
        while ((dp = readdir(dirp)) != NULL) {
-               if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
+               if (is_dotdir_dirent(dp))
                        continue;
                if (postfix)
                        snprintf(d, PATH_MAX - len, "%s%s", dp->d_name, postfix);
index dad88978d1e4e6a3ae06bd8a668879c896d4bdb2..f5d48badb386ac3e8196aa4a86211e652d70f4a3 100644 (file)
@@ -53,6 +53,7 @@
 #include "pathnames.h"
 #include "sysfs.h"
 #include "monotonic.h"
+#include "fileutils.h"
 
 /*
  * sg_io_hdr_t driver_status -- see kernel include/scsi/sg.h
@@ -779,7 +780,7 @@ static int umount_partitions(struct eject_control *ctl)
 
        /* scan for partition subdirs */
        while ((d = readdir(dir))) {
-               if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
+               if (is_dotdir_dirent(d))
                        continue;
 
                if (sysfs_blkdev_is_partition_dirent(dir, d, ctl->device)) {
index ab8c2a141c4795ab984255b3abbebd970c888d66..69ae77080c25b74b12c7689e57427917748eef3a 100644 (file)
@@ -39,6 +39,7 @@
 #include "nls.h"
 #include "closestream.h"
 #include "statfs_magic.h"
+#include "fileutils.h"
 
 #ifndef MS_MOVE
 #define MS_MOVE 8192
@@ -81,7 +82,7 @@ static int recursiveRemove(int fd)
                        break;  /* end of directory */
                }
 
-               if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
+               if (is_dotdir_dirent(d))
                        continue;
 #ifdef _DIRENT_HAVE_D_TYPE
                if (d->d_type == DT_DIR || d->d_type == DT_UNKNOWN)