From nobody Wed Aug 24 19:44:08 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 4MCc3r6HTSz4Zhcp; Wed, 24 Aug 2022 19:44:08 +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 4MCc3r5bLYz3Tqm; Wed, 24 Aug 2022 19:44:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661370248; 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=H7AxLhBFgNfvwe+zvR1Uqw1KYnKHnYWQqz6x/CzM/kw=; b=Myal4h9+xa4/Nb7wef6jbeiyUI/Q1yilUhJ1MhgtK0O9ncnqFaKY+E+vRAvBOu0G0NhYQC T2nE6cMGiwDieHzq0eb1cuwKzL4NJoPh/e/hMmWgSRCMPfGVOWPRNY3CYi7h+9SYvKj+yu 4uXXXFsvVRCPSoIwOTAeb1Z5EwBTlL2ldqOZju72BhFqP0FsGePOjot5H20MVdQ28SwbIA PFWv14dkR187CJVy75s4nsApGv4fo5t1JZ2W4TJDyAenTizddG8qw6X+IwjRDca68z0nIu VPBxgMyag0i/sG6G0rgljG4MAyIIuiWOs62+XrRLgjfLKrqYSbg9Amvs/MjcFg== 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 4MCc3r4cvmzLKG; Wed, 24 Aug 2022 19:44:08 +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 27OJi88r096986; Wed, 24 Aug 2022 19:44:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27OJi8Y4096985; Wed, 24 Aug 2022 19:44:08 GMT (envelope-from git) Date: Wed, 24 Aug 2022 19:44:08 GMT Message-Id: <202208241944.27OJi8Y4096985@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: a294e679738b - main - Document 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: a294e679738bb4d2254c0ff416d40f6d6329754a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661370248; 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=H7AxLhBFgNfvwe+zvR1Uqw1KYnKHnYWQqz6x/CzM/kw=; b=LeyU4cqtV0gp7bPPtLTNwQgrRMFzTBgkZO0E791PDrVDh6gXDOIkS9gzfQEaP7obJzBbB5 y+qu3fKaESa2out17jSAjL8/2iHUntYtyJo3t7uclVrBjX4blGcsiUuzmS1Hlm2xHOH99l vMHEZ3xlI3dCak+wdGnOPaIQH+nusDxAeYx6/vRUgYrVnZ8HNVxN87Wj4lfhJmAHerJRdl AnLehU5lMw2AlLQX+xMrT0H/R6FBeO3F+SDaT1WERMDkB+2T5aW3NftE3LHzS3zKYclNND YMke8KM52gNsgJVuCdrdXphDZsRE+cslN3lkjn7ddYqrYES8bSRxnMgywzUIrQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1661370248; a=rsa-sha256; cv=none; b=uqxaz5fk9QB6+QVDHEaiWlAGyOCmXcxOW+mVM/WzrNJrXB4LFmgVtRNKRv+HR8fmIkpp/Q RnsYU9fExv5m+pOPXcUbFn4pu0vmQrhOAsDpJyTL0ISR9IMhsy2oyKPfg+tsm50J0QiRpM DDNbqpQU0IRQfJM1Cl7vSnX+/968dTcfbDTYq1YPsrJ170H5PzMDcU9fTMpkzn2j5sgVEA Ba284iJvpxGvSGqtThw5EDIFkv/8VSWQTOvW4pL5oUAji0kqELiwlT+4kepQ9cjdjSKkDS BMZ1WJOOM70o0TZR1w+zSHKf0/qMWKLa/Vgy22O00clqeFhwABou2Af7BZNjbA== 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=a294e679738bb4d2254c0ff416d40f6d6329754a commit a294e679738bb4d2254c0ff416d40f6d6329754a Author: Konstantin Belousov AuthorDate: 2022-08-23 03:40:06 +0000 Commit: Konstantin Belousov CommitDate: 2022-08-24 19:26:01 +0000 Document scandirat(3) Reviewed by: emaste, gbe (man pages), imp, kevans, markj, Aymeric Wibo Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D36301 --- lib/libc/gen/Makefile.inc | 1 + lib/libc/gen/scandir.3 | 49 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 161c061a1742..6d0e542a1f7b 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -494,6 +494,7 @@ MLINKS+=rand48.3 _rand48.3 \ rand48.3 srand48.3 MLINKS+=recv.2 recvmmsg.2 MLINKS+=scandir.3 alphasort.3 \ + scandir.3 scandirat.3 \ scandir.3 scandir_b.3 MLINKS+=sem_open.3 sem_close.3 \ sem_open.3 sem_unlink.3 diff --git a/lib/libc/gen/scandir.3 b/lib/libc/gen/scandir.3 index 47057fc647fc..b533b33ce7a7 100644 --- a/lib/libc/gen/scandir.3 +++ b/lib/libc/gen/scandir.3 @@ -28,11 +28,12 @@ .\" @(#)scandir.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd January 3, 2010 +.Dd August 23, 2022 .Dt SCANDIR 3 .Os .Sh NAME .Nm scandir , +.Nm scandirat , .Nm scandir_b , .Nm alphasort .Nd scan a directory @@ -47,6 +48,14 @@ .Fa "int \*(lp*select\*(rp\*(lpconst struct dirent *\*(rp" .Fa "int \*(lp*compar\*(rp\*(lpconst struct dirent **, const struct dirent **\*(rp" .Fc +.Ft +.Fo scandirat +.Fa int dirfd +.Fa "const char *dirname" +.Fa "struct dirent ***namelist" +.Fa "int \*(lp*select\*(rp\*(lpconst struct dirent *\*(rp" +.Fa "int \*(lp*compar\*(rp\*(lpconst struct dirent **, const struct dirent **\*(rp" +.Fc .Ft int .Fo scandir_b .Fa "const char *dirname" @@ -102,6 +111,39 @@ The memory allocated for the array can be deallocated with by freeing each pointer in the array and then the array itself. .Pp The +.Fn scandirat +function is similar to +.Fn scandir , +but takes an additional +.Fa dirfd +argument. +If the supplied +.Fa dirname +is absolute, the function's behavior is identical to that of +.Fn scandir , +the +.Fa dirfd +argument is unused. +If +.Fa dirname +is relative, +.Fa dirfd +must be a valid file descriptor referencing a directory, in +which case the +.Fa dirname +lookup is performed relative to the directory referenced by +.Fa dirfd . +If +.Fa dirfd +has the special value +.Va AT_FDCWD , +then the current process directory is used as the base for +relative lookups. +See +.Xr openat 2 +for additional details. +.Pp +The .Fn scandir_b function behaves in the same way as .Fn scandir , @@ -114,6 +156,7 @@ Returns \-1 if the directory cannot be opened for reading or if .Xr malloc 3 cannot allocate enough memory to hold all the data structures. .Sh SEE ALSO +.Xr openat 2 , .Xr directory 3 , .Xr malloc 3 , .Xr qsort 3 , @@ -126,3 +169,7 @@ and .Fn alphasort functions appeared in .Bx 4.2 . +The +.Fn scandirat +function was added in +.Fx 14.0 .