From: Karel Zak Date: Mon, 27 Jun 2022 11:00:55 +0000 (+0200) Subject: libblkid: simplify 'leaf' detection X-Git-Tag: v2.39-rc1~592 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d12e166daaa160e8d9c81b64dcd616d7672bfaf1;p=thirdparty%2Futil-linux.git libblkid: simplify 'leaf' detection References: https://github.com/util-linux/util-linux/pull/1729 Signed-off-by: Karel Zak --- diff --git a/libblkid/src/devname.c b/libblkid/src/devname.c index 2e64ddac46..3f48032327 100644 --- a/libblkid/src/devname.c +++ b/libblkid/src/devname.c @@ -155,20 +155,16 @@ static const char *dirlist[] = { "/dev", "/devfs", "/devices", NULL }; */ static int is_dm_leaf(const char *devname) { - struct dirent *de; - DIR *dir; - char path[NAME_MAX + 18 + 1]; - int ret = 1; + DIR *dir; + char path[NAME_MAX + 18 + 1]; + int ret; snprintf(path, sizeof(path), "/sys/block/%s/holders", devname); if ((dir = opendir(path)) == NULL) return 0; - while ((de = readdir(dir)) != NULL) { - if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) - continue; - ret = 0; - break; - } + + ret = xreaddir(dir) == NULL ? 1 : 0; /* 'leaf' has no entries */ + closedir(dir); return ret; }