From nobody Thu Feb 5 15:27:32 2026 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 4f6Lgn2ffTz6Qkqp for ; Thu, 05 Feb 2026 15:27:33 +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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4f6Lgm6JmBz3XfN for ; Thu, 05 Feb 2026 15:27:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1770305252; 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=DcriEgjb1rjQ/hsh/V0yqCnw5Q6E9Q9pRh1F0y2ZRoQ=; b=JXavN01f1+WCm/ZvXEqYpjxXFuZSV22Pf+IBhh8mDPQudHwaMyQarHQHWmnvkk/anXCNHs QuqnL27o5p4jMMJ0SlhRmkverVZox97E5cX8u1W1AxdFh0O1K1vroLgQnaBV6aJ3VMrzm8 hB7wwehOpLks3CJWw+SXpe1tECtrYNjn4a6A6yIKX+JHfh2z3KB51HPm5nIFjgoVJ/C+Kq mIKx/M+WhdGsCcZrwEQDtDyCEJgIUAOzeE3rAs7hUFWIoCQQqpygUwFmKsnv4hwz7yFigk a4uTAe+AuHjNU716ncFPmLTZ+ThIqCVBACG32tPVpMBeUc/fHVSW94BIKtDK4A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1770305252; a=rsa-sha256; cv=none; b=B0tyxQ5VK4nsWUySIxNognfquJ46gS/BFvna6T1L+jWsV1XTGPlWe8HnvMA8wS0Z1eVIpD e7fTrEmJMB24gSWPpHocO6rRJE8QaAq3BJZpM0OS2b+WMnZDfL9xOHs2PdjennNEBlhH7p m+xZZKQtHwnlsc74lFK+kli5FZ4CxoEsA9Xrx55WNfJkIWPM4GBtaBYxSr2lSbR87JHqcv qnexTIlIyY2dUnuFVjdrLRhNjIsI2Ci1C1sutizAw0IEuq3VBEC2Gy+xHRH991qzv3T7u4 IvP5zVyLNINLTwTlRB8BwWDWIVxZkxcKefWBiXg4VECQhzaL0EjCSbQK/gE2pQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1770305252; 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=DcriEgjb1rjQ/hsh/V0yqCnw5Q6E9Q9pRh1F0y2ZRoQ=; b=D2UZomnUwgty2znS0sEPJUXiGt+KPWeAcEbtstUDXDSeGBojov61ECarAKUmsB/M+sZLOL tOunftChRU3OGqjsEjcY3EnYnp9DlWsDFYW7PnXojap6hxr+E+swFSluxjW6nJML7RRWSe gldUpPXscUORtYeUJB1mjo43gUKMijt+x1zNtDESOANvTZ4HjFjFmQ7iA0i6FBx4jbI5ll co3yDZo4E59aldSvXOPtZPYbd/NXutV0FwAq5eay8OvmEfTGc23i9rArLnVPlzmP8DF4Lt Oy2njRjPpxQFIqe/OxFAdeVky0ly5O/PK4MFBAMULNnFZZJc1Z19/XQGeGltjw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4f6Lgm5v43zbJq for ; Thu, 05 Feb 2026 15:27:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 182dc by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 05 Feb 2026 15:27:32 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: b614c9893fa3 - stable/14 - libc: Clean up *dir() code 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: b614c9893fa38771075d1f329763a0151b53b86d Auto-Submitted: auto-generated Date: Thu, 05 Feb 2026 15:27:32 +0000 Message-Id: <6984b6e4.182dc.694db3be@gitrepo.freebsd.org> The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=b614c9893fa38771075d1f329763a0151b53b86d commit b614c9893fa38771075d1f329763a0151b53b86d Author: Dag-Erling Smørgrav AuthorDate: 2026-02-02 15:46:53 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-02-05 14:48:36 +0000 libc: Clean up *dir() code Fix style nits (mostly whitespace issues) and clean up the manual page. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D55024 (cherry picked from commit 387ae6390534b6e9b48931840e7bc76eeb0b258d) --- lib/libc/gen/closedir.c | 1 - lib/libc/gen/directory.3 | 78 +++++++++++++++++++++++++----------------------- lib/libc/gen/dirfd.c | 3 -- lib/libc/gen/fdopendir.c | 1 + lib/libc/gen/opendir.c | 1 - lib/libc/gen/opendir2.c | 1 - lib/libc/gen/rewinddir.c | 1 - lib/libc/gen/scandir.c | 2 -- lib/libc/gen/telldir.c | 4 +-- 9 files changed, 43 insertions(+), 49 deletions(-) diff --git a/lib/libc/gen/closedir.c b/lib/libc/gen/closedir.c index 16f9bff452e4..18444bb984fb 100644 --- a/lib/libc/gen/closedir.c +++ b/lib/libc/gen/closedir.c @@ -70,6 +70,5 @@ fdclosedir(DIR *dirp) int closedir(DIR *dirp) { - return (_close(fdclosedir(dirp))); } diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3 index 0314ab90ca24..3a121dcafb8c 100644 --- a/lib/libc/gen/directory.3 +++ b/lib/libc/gen/directory.3 @@ -27,7 +27,7 @@ .\" .\" @(#)directory.3 8.1 (Berkeley) 6/4/93 .\" -.Dd August 1, 2020 +.Dd January 31, 2026 .Dt DIRECTORY 3 .Os .Sh NAME @@ -88,13 +88,6 @@ and returns a pointer to be used to identify the .Em directory stream in subsequent operations. -The pointer -.Dv NULL -is returned if -.Fa filename -cannot be accessed, or if it cannot -.Xr malloc 3 -enough memory to hold the whole thing. .Pp The .Fn fdopendir @@ -136,14 +129,6 @@ or .Fn closedir on the same .Em directory stream . -The function returns -.Dv NULL -upon reaching the end of the directory or on error. -In the event of an error, -.Va errno -may be set to any of the values documented for the -.Xr getdirentries 2 -system call. .Pp The .Fn readdir_r @@ -168,10 +153,6 @@ upon reaching the end of the directory .Fa result is set to .Dv NULL . -The -.Fn readdir_r -function -returns 0 on success or an error number to indicate failure. .Pp The .Fn telldir @@ -181,12 +162,9 @@ returns a token representing the current location associated with the named Values returned by .Fn telldir are good only for the lifetime of the -.Dv DIR -pointer, -.Fa dirp , +.Em directory stream from which they are derived. -If the directory is closed and then -reopened, prior values returned by +If the directory is closed and then reopened, prior values returned by .Fn telldir will no longer be valid. Values returned by @@ -219,28 +197,22 @@ The function closes the named .Em directory stream -and frees the structure associated with the -.Fa dirp -pointer, -returning 0 on success. -On failure, \-1 is returned and the global variable -.Va errno -is set to indicate the error. +and frees the structure associated with +.Fa dirp . .Pp The .Fn fdclosedir function is equivalent to the .Fn closedir -function except that this function returns directory file descriptor instead of -closing it. +function except that it returns the file descriptor associated with +.Fa dirp +instead of closing it. .Pp The .Fn dirfd function -returns the integer file descriptor associated with the named -.Em directory stream , -see -.Xr open 2 . +returns the file descriptor associated with +.Fa dirp . .Sh EXAMPLES Sample code which searches a directory for entry ``name'' is: .Bd -literal -offset indent @@ -257,6 +229,36 @@ while ((dp = readdir(dirp)) != NULL) { (void)closedir(dirp); return (NOT_FOUND); .Ed +.Sh RETURN VALUES +The +.Fn opendir +and +.Fn fdopendir +functions return a pointer to the new +.Em directory stream +on success and +.Dv NULL +on failure. +.Pp +The +.Fn readdir +function returns a pointer to a directory entry on success and +.Dv NULL +on failure. +The +.Fn readdir_r +function returns 0 on success and an error number on failure. +.Pp +The +.Fn telldir +function returns a nonnegative value on success and -1 on failure. +.Pp +The +.Fn closedir +function returns 0 on success and -1 on failure. +The +.Fn fdclosedir +function returns an open file descriptor on success and -1 on failure. .Sh ERRORS The .Fn opendir diff --git a/lib/libc/gen/dirfd.c b/lib/libc/gen/dirfd.c index 85090bd4da6c..ba8f52845b4e 100644 --- a/lib/libc/gen/dirfd.c +++ b/lib/libc/gen/dirfd.c @@ -27,8 +27,6 @@ */ #include "namespace.h" -#include - #include #include "un-namespace.h" @@ -37,6 +35,5 @@ int dirfd(DIR *dirp) { - return (_dirfd(dirp)); } diff --git a/lib/libc/gen/fdopendir.c b/lib/libc/gen/fdopendir.c index 9393cbe28f85..05e1a09fd00c 100644 --- a/lib/libc/gen/fdopendir.c +++ b/lib/libc/gen/fdopendir.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "un-namespace.h" #include "gen-private.h" diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c index af36e0077ef1..c38a5e753e6b 100644 --- a/lib/libc/gen/opendir.c +++ b/lib/libc/gen/opendir.c @@ -44,6 +44,5 @@ __SCCSID("@(#)opendir.c 8.8 (Berkeley) 5/1/95"); DIR * opendir(const char *name) { - return (__opendir2(name, DTF_HIDEW | DTF_NODUP)); } diff --git a/lib/libc/gen/opendir2.c b/lib/libc/gen/opendir2.c index f85cdb9f6c75..7102974e7eca 100644 --- a/lib/libc/gen/opendir2.c +++ b/lib/libc/gen/opendir2.c @@ -68,7 +68,6 @@ __opendir2(const char *name, int flags) static int opendir_compar(const void *p1, const void *p2) { - return (strcmp((*(const struct dirent * const *)p1)->d_name, (*(const struct dirent * const *)p2)->d_name)); } diff --git a/lib/libc/gen/rewinddir.c b/lib/libc/gen/rewinddir.c index bc072d2826ea..aaa7ffbeeed9 100644 --- a/lib/libc/gen/rewinddir.c +++ b/lib/libc/gen/rewinddir.c @@ -45,7 +45,6 @@ __SCCSID("@(#)rewinddir.c 8.1 (Berkeley) 6/8/93"); void rewinddir(DIR *dirp) { - if (__isthreaded) _pthread_mutex_lock(&dirp->dd_lock); dirp->dd_flags &= ~__DTF_SKIPREAD; /* current contents are invalid */ diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c index 3f13248a3f2b..a223ef258569 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -234,14 +234,12 @@ scandirat(int dirfd, const char *dirname, struct dirent ***namelist, int alphasort(const struct dirent **d1, const struct dirent **d2) { - return (strcoll((*d1)->d_name, (*d2)->d_name)); } int versionsort(const struct dirent **d1, const struct dirent **d2) { - return (strverscmp((*d1)->d_name, (*d2)->d_name)); } diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c index ac0e2e50f9b3..97df95ea8416 100644 --- a/lib/libc/gen/telldir.c +++ b/lib/libc/gen/telldir.c @@ -55,7 +55,7 @@ telldir(DIR *dirp) if (__isthreaded) _pthread_mutex_lock(&dirp->dd_lock); - /* + /* * Outline: * 1) If the directory position fits in a packed structure, return that. * 2) Otherwise, see if it's already been recorded in the linked list @@ -97,7 +97,7 @@ telldir(DIR *dirp) LIST_INSERT_HEAD(&dirp->dd_td->td_locq, lp, loc_lqe); } ddloc.i.is_packed = 0; - /* + /* * Technically this assignment could overflow on 32-bit architectures, * but we would get ENOMEM long before that happens. */