From 19df31a23a3a5ab08abde6cea7f4b8bfd44fd07c Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Sun, 26 Dec 2021 14:48:12 +0100 Subject: libq/scandirat: add filter_self_parent func Signed-off-by: Fabian Groffen --- libq/scandirat.c | 18 +++++++++++++++--- libq/scandirat.h | 9 +++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'libq') diff --git a/libq/scandirat.c b/libq/scandirat.c index f28ba0d..ec4b691 100644 --- a/libq/scandirat.c +++ b/libq/scandirat.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2019 Gentoo Foundation + * Copyright 2005-2021 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2010 Ned Ludd - @@ -87,9 +87,21 @@ scandir_free(struct dirent **de, int cnt) } int -filter_hidden(const struct dirent *dentry) +filter_hidden(const struct dirent *de) { - if (dentry->d_name[0] == '.') + if (de->d_name[0] == '.') return 0; return 1; } + +int +filter_self_parent(const struct dirent *de) +{ + if (de->d_name[0] == '.' && + (de->d_name[1] == '\0' || + (de->d_name[1] == '.' && + de->d_name[2] == '\0'))) + return 0; + + return 1; +} diff --git a/libq/scandirat.h b/libq/scandirat.h index 950cbb1..1ac2b50 100644 --- a/libq/scandirat.h +++ b/libq/scandirat.h @@ -1,6 +1,10 @@ /* - * Copyright 2005-2019 Gentoo Foundation + * Copyright 2005-2021 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 + * + * Copyright 2005-2010 Ned Ludd - + * Copyright 2005-2014 Mike Frysinger - + * Copyright 2021- Fabian Groffen - */ #ifndef _SCANDIRAT_H @@ -19,6 +23,7 @@ int scandirat( #endif void scandir_free(struct dirent **de, int cnt); -int filter_hidden(const struct dirent *dentry); +int filter_hidden(const struct dirent *de); +int filter_self_parent(const struct dirent *de); #endif -- cgit v1.2.3-65-gdbad