Skip to content

Commit b3876d4

Browse files
committed
*: 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@gentoo.org>
1 parent 29bbfe5 commit b3876d4

File tree

4 files changed

+7
-31
lines changed

4 files changed

+7
-31
lines changed

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ am__define_uniq_tagged_files = \
435435
done | $(am__uniquify_input)`
436436
DIST_SUBDIRS = $(SUBDIRS)
437437
am__DIST_COMMON = $(dist_man_MANS) $(srcdir)/Makefile.in \
438-
$(srcdir)/config.h.in COPYING README.md ar-lib compile \
438+
$(srcdir)/config.h.in COPYING INSTALL README.md ar-lib compile \
439439
config.guess config.sub depcomp install-sh ltmain.sh missing
440440
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
441441
distdir = $(PACKAGE)-$(VERSION)

libq/tree.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,6 @@ tree_filter_cat(const struct dirent *de)
287287
int i;
288288
bool founddash;
289289

290-
#ifdef DT_UNKNOWN
291-
/* cat must be a dir */
292-
if (de->d_type != DT_UNKNOWN &&
293-
de->d_type != DT_DIR &&
294-
de->d_type != DT_LNK)
295-
return 0;
296-
#endif
297-
298290
/* PMS 3.1.1 */
299291
founddash = false;
300292
for (i = 0; de->d_name[i] != '\0'; i++) {

main.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -941,32 +941,22 @@ read_repos_conf(const char *configroot, const char *repos_conf, char **primary)
941941
} else {
942942
for (i = 0; i < count; ++i) {
943943
const char *name = confs[i]->d_name;
944+
struct stat st;
944945

946+
/* skip self, parent, and "hidden" files */
945947
if (name[0] == '.' || name[0] == '\0')
946948
continue;
947949

948950
/* Exclude backup files (aka files with ~ as postfix). */
949951
if (name[strlen(name) - 1] == '~')
950952
continue;
951953

952-
#ifdef DT_UNKNOWN
953-
if (confs[i]->d_type != DT_UNKNOWN &&
954-
confs[i]->d_type != DT_REG &&
955-
confs[i]->d_type != DT_LNK)
956-
continue;
957-
#endif
958-
959954
xasprintf(&sub_conf, "%s/%s", top_conf, name);
960955

961-
#ifdef DT_UNKNOWN
962-
if (confs[i]->d_type != DT_REG)
963-
#endif
964-
{
965-
struct stat st;
966-
if (stat(sub_conf, &st) || !S_ISREG(st.st_mode)) {
967-
free(sub_conf);
968-
continue;
969-
}
956+
/* skip non-files */
957+
if (stat(sub_conf, &st) != 0 || !S_ISREG(st.st_mode)) {
958+
free(sub_conf);
959+
continue;
970960
}
971961

972962
read_one_repos_conf(sub_conf, primary);

qmerge.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,7 @@ install_mask_check_dir(
426426
int j;
427427
enum inc_exc mode;
428428
enum inc_exc child_mode;
429-
#ifndef DT_DIR
430429
struct stat s;
431-
#endif
432430
char *npth = qpth + strlen(qpth);
433431

434432
cnt = scandirat(fd, ".", &files, filter_self_parent, alphasort);
@@ -472,13 +470,9 @@ install_mask_check_dir(
472470
continue;
473471
}
474472

475-
#ifdef DT_DIR
476-
if (files[j]->d_type == DT_DIR) {
477-
#else
478473
if (fstatat(fd, files[j]->d_name, &s, AT_SYMLINK_NOFOLLOW) != 0)
479474
continue;
480475
if (S_ISDIR(s.st_mode)) {
481-
#endif
482476
int subfd = openat(fd, files[j]->d_name, O_RDONLY);
483477
if (subfd < 0)
484478
continue;

0 commit comments

Comments
 (0)