From nobody Wed Aug 24 19:44:07 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MCc3q5QLQz4Zhcn; Wed, 24 Aug 2022 19:44:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MCc3q4wTVz3Tn4; Wed, 24 Aug 2022 19:44:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661370247; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OKFQePeg0YjRp2e8KFctwNLHrYFe9S0EYnKlHixR2X4=; b=DYwZ0nAiaTfaj8Vl2/si2M1p1H3jpwKscd5pADyADb02aWnqQWSyAHh8rJkS0VYdK/4g66 4Jugk4psOnqnNYVzkfZiGp2kBOnPNayEV/M32Tjd2jdZq4AEd7l/i78hxPCcGaJK8NlyQ4 ZqwF/uQkGGp7pdMeWiTfI/uhp7h+RRpHIGmRdDQk3li/svFc+CLX6wdIUsCs9ISepE1uqV OYoGi/qWnwuGLdfQETLkOJ2/wzg7lKm4kwUERyMNZDXJk0Q9SSch0V6xEGAfHvgx6/miEN cp8lMZBBy9YR2iQab0yAjgbFwogNhnlJQdEeF/UM4KFuInJC+Bt9ygG4OzZ3+g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MCc3q42BgzKtS; Wed, 24 Aug 2022 19:44:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 27OJi7Na096957; Wed, 24 Aug 2022 19:44:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27OJi7XQ096956; Wed, 24 Aug 2022 19:44:07 GMT (envelope-from git) Date: Wed, 24 Aug 2022 19:44:07 GMT Message-Id: <202208241944.27OJi7XQ096956@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 9fb8e8eede5b - main - libc: add scandirat(3) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9fb8e8eede5b48eda7dc39f61d815595c14e5752 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661370247; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OKFQePeg0YjRp2e8KFctwNLHrYFe9S0EYnKlHixR2X4=; b=LyVbiQtBhdzJcla/l8ZIp88BWSo2hG9ggBSIo1ajJ/FSdJdqa5UU9B8KcjgoDvfrxV8SLF H0XsAn7/PHTnaIe/ZqiXM3xhWDsY2gVPad1qEf90wFLjt1s33V+aF/cHTnsUpie1tTrdRK r/lNB/oguhNy0D8hBQXEaKyLLkA/WL7WMyqBGd45kbD6C2EiSa0qNoNI5OETTp8+skh6JP L32tGJxIK+AAK+Q36e0LSmsSjvJungmO+p9IuCPzLNMOUJzpBBlRi0+9t14rwwycRXe6hM njO5NVXhgAtzAeqn9ZaZVQJGNXxZjjlB8y3a0astKxLnbgphC0N8bZtkeAsGUg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1661370247; a=rsa-sha256; cv=none; b=arjlPsLN+GNfREJJOJy/TbVx1CeASaaIg81q5A0500sXgxJRtPHoCMtvv1NonsYIStN8TE HbkX6eMp4T5JBjMXy51+ve8RLWY/dcKxZNb92m983tvvH5lVyIIPrPLraDRg9tCkR1pQu/ qzPRY+fnWU4izdgUCByNc1aJ8ItHWTrOr6Q1z2XGfpjn9CvRhCPee/awkGvAHq/I7V7wyx BjPzSbkkToSY1oKte1EENgrFn0ZAqgkdENzMhZOeP7fc1NE9LbKEe25VLILOSUBtA3uXM+ aAcm7Np7WrZqgzfnrDY9NrMm4IQo2hIW7HIK4KM307fHtWezwSjHvclJ0Vk4AA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=9fb8e8eede5b48eda7dc39f61d815595c14e5752 commit 9fb8e8eede5b48eda7dc39f61d815595c14e5752 Author: Konstantin Belousov AuthorDate: 2022-08-23 03:30:06 +0000 Commit: Konstantin Belousov CommitDate: 2022-08-24 19:26:00 +0000 libc: add scandirat(3) Reviewed by: emaste, imp, kevans, markj, Aymeric Wibo Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D36301 --- include/dirent.h | 5 +++++ lib/libc/gen/Symbol.map | 1 + lib/libc/gen/scandir.c | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/include/dirent.h b/include/dirent.h index 702153e28fc0..047206258471 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -131,6 +131,11 @@ int scandir_b(const char *, struct dirent ***, int (^)(const struct dirent **, const struct dirent **)); #endif #endif +#if __BSD_VISIBLE +int scandirat(int, const char *, struct dirent ***, + int (*)(const struct dirent *), int (*)(const struct dirent **, + const struct dirent **)); +#endif #if __XSI_VISIBLE void seekdir(DIR *, long); long telldir(DIR *); diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map index 012c9ff11f04..74676ffe2270 100644 --- a/lib/libc/gen/Symbol.map +++ b/lib/libc/gen/Symbol.map @@ -439,6 +439,7 @@ FBSD_1.7 { posix_spawn_file_actions_addchdir_np; posix_spawn_file_actions_addclosefrom_np; posix_spawn_file_actions_addfchdir_np; + scandirat; sched_getaffinity; sched_setaffinity; sched_getcpu; diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c index 4cfc823e4f94..3a891b0ad3f2 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -42,8 +42,10 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include +#include #include #include +#include #include "un-namespace.h" #ifdef I_AM_SCANDIR_B @@ -159,6 +161,25 @@ scandir(const char *dirname, struct dirent ***namelist, } #ifndef I_AM_SCANDIR_B +int +scandirat(int dirfd, const char *dirname, struct dirent ***namelist, + int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **, + const struct dirent **)) +{ + DIR *dirp; + int fd; + + fd = _openat(dirfd, dirname, O_RDONLY | O_DIRECTORY | O_CLOEXEC); + if (fd == -1) + return (-1); + dirp = fdopendir(fd); + if (dirp == NULL) { + _close(fd); + return (-1); + } + return (scandir_dirp(dirp, namelist, select, dcomp)); +} + /* * Alphabetic order comparison routine for those who want it. * POSIX 2008 requires that alphasort() uses strcoll().