commit: b3876d4c9bf97ab7389bbe000ee083c5f8085114
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri Aug 29 15:34:30 2025 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Aug 29 15:34:30 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b3876d4c
*: drop usage of dirent d_type
d_type is not defined by POSIX in dirent, but in posix_getdent. The
latter is not available on most platforms, and gnulib doesn't provide a
wrapper. Realistically, using stat is portable, and the places in which
we really need to know the type are very limited. So drop using d_type.
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
Makefile.in | 2 +-
libq/tree.c | 8 --------
main.c | 22 ++++++----------------
qmerge.c | 6 ------
4 files changed, 7 insertions(+), 31 deletions(-)
diff --git a/Makefile.in b/Makefile.in
index 8acc87e..6ce782f 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -435,7 +435,7 @@ am__define_uniq_tagged_files = \
done | $(am__uniquify_input)`
DIST_SUBDIRS = $(SUBDIRS)
am__DIST_COMMON = $(dist_man_MANS) $(srcdir)/Makefile.in \
- $(srcdir)/config.h.in COPYING README.md ar-lib compile \
+ $(srcdir)/config.h.in COPYING INSTALL README.md ar-lib compile \
config.guess config.sub depcomp install-sh ltmain.sh missing
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION)
diff --git a/libq/tree.c b/libq/tree.c
index 89393f3..643c7a0 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -287,14 +287,6 @@ tree_filter_cat(const struct dirent *de)
int i;
bool founddash;
-#ifdef DT_UNKNOWN
- /* cat must be a dir */
- if (de->d_type != DT_UNKNOWN &&
- de->d_type != DT_DIR &&
- de->d_type != DT_LNK)
- return 0;
-#endif
-
/* PMS 3.1.1 */
founddash = false;
for (i = 0; de->d_name[i] != '\0'; i++) {
diff --git a/main.c b/main.c
index 5e6cae2..c14fe7f 100644
--- a/main.c
+++ b/main.c
@@ -941,7 +941,9 @@ read_repos_conf(const char *configroot, const char
*repos_conf, char **primary)
} else {
for (i = 0; i < count; ++i) {
const char *name = confs[i]->d_name;
+ struct stat st;
+ /* skip self, parent, and "hidden" files */
if (name[0] == '.' || name[0] == '\0')
continue;
@@ -949,24 +951,12 @@ read_repos_conf(const char *configroot, const char
*repos_conf, char **primary)
if (name[strlen(name) - 1] == '~')
continue;
-#ifdef DT_UNKNOWN
- if (confs[i]->d_type != DT_UNKNOWN &&
- confs[i]->d_type != DT_REG &&
- confs[i]->d_type != DT_LNK)
- continue;
-#endif
-
xasprintf(&sub_conf, "%s/%s", top_conf, name);
-#ifdef DT_UNKNOWN
- if (confs[i]->d_type != DT_REG)
-#endif
- {
- struct stat st;
- if (stat(sub_conf, &st) ||
!S_ISREG(st.st_mode)) {
- free(sub_conf);
- continue;
- }
+ /* skip non-files */
+ if (stat(sub_conf, &st) != 0 || !S_ISREG(st.st_mode)) {
+ free(sub_conf);
+ continue;
}
read_one_repos_conf(sub_conf, primary);
diff --git a/qmerge.c b/qmerge.c
index fcdf45c..1e52704 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -426,9 +426,7 @@ install_mask_check_dir(
int j;
enum inc_exc mode;
enum inc_exc child_mode;
-#ifndef DT_DIR
struct stat s;
-#endif
char *npth = qpth + strlen(qpth);
cnt = scandirat(fd, ".", &files, filter_self_parent, alphasort);
@@ -472,13 +470,9 @@ install_mask_check_dir(
continue;
}
-#ifdef DT_DIR
- if (files[j]->d_type == DT_DIR) {
-#else
if (fstatat(fd, files[j]->d_name, &s, AT_SYMLINK_NOFOLLOW) != 0)
continue;
if (S_ISDIR(s.st_mode)) {
-#endif
int subfd = openat(fd, files[j]->d_name, O_RDONLY);
if (subfd < 0)
continue;