From nobody Thu Feb 05 15:26:55 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 4f6Lg33SXVz6Qkkt for ; Thu, 05 Feb 2026 15:26:55 +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 4f6Lg32hXwz3W5W for ; Thu, 05 Feb 2026 15:26:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1770305215; 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=86lCfoz8nfGdc63k1u6uLzc6qQ/Bzo+pfn22ucP3QtM=; b=E7vj3tVlqLH2UT7vmN5kSHqoyx00iQZ9kLapfcPvU1At6kD+Xs3vlx/bHUqGcQuFI6RSMt Uq7+Lu/0hmvdDtEfCfaX5TeWlZGjX4cw6b0EIk10E3wpk5bUpGQ3seemK932MklUGO9JoD yw54GhFbEaW88xkE7qzd8OlMYL8REoSB02vtoFgZPL0JG09N8xddm84CcUdUX3/bG5tHNX eUAmiVby1XifeO93xivTZ4M/6YVB2teSQX7nuxB4QRC2lHyuuW4xJYos83BQyr4+85+4N4 B9cZ58yKDpv49/hsFe02EsYKINEaOD5Q+jf6IiL8yKODeTw2zc+XuKqL5LKJ8w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1770305215; a=rsa-sha256; cv=none; b=QIZYTPdqnU4+StZTH/CA8Q2n2I901rSiIx65KZKynYHgNyGjQaPWcFtieRkEjtWBVbvE6M 54NRLX1mbzHCtV7SMHrqNwOy7jLUqrFf3AaVcoVS5ppXGuTHBhVNpjhedMJbAoSjjEpH2p VeXI0k3jvXP5Q4c0UJGXhTvAh3KNSHkETE3/RzKgUJ4g38DS0er5h8DVwyNI2YrXmHmsDr Okwx7jQCFqwAvn/lndcCQooigJK+UWz956WuI3wpq952oBkgP/a3TTBp5ja8TjfBDp8xoh El56KUsKHaRU05xdc1cHJIrH16G/0BcUcF6I7baratXX6X2F29iEnIqBC6ka1w== 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=1770305215; 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=86lCfoz8nfGdc63k1u6uLzc6qQ/Bzo+pfn22ucP3QtM=; b=pLnbtiHNqtgnZB1YGLAfzL1/r8zFyrYltggpG+AlUg6u5p8Y1ePPyPmKyiuYEGX0HKlljB sm5VcpmZS9wQWjwjphaux6ZmXaNc/XdHgHpC7KHSi1Mhus6l/j+kK/NcSMG2QcTWPLqIoC FTRxN3WRKBJ8YXPZOeHUWWIPBJfQ34kaV1VTdh8htghoEC1kpGpZFjvXQEz7VI/0PHwzkc z0H8KK4NW5gw9M/H38IlveW1SS0Z79bcIgfFgGOaepAKQlYd2TLJPwCUdX5IHL0uM/RpwM FCf8VJJ9wIHIstSM+l12Z74IxjyP7tr5BfJhcPQJTx1oyuqtQ2EYdrOAvtzUEQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4f6Lg329BFzbx5 for ; Thu, 05 Feb 2026 15:26:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1808f by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 05 Feb 2026 15:26:55 +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: 762729bdd4d3 - stable/15 - 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/15 X-Git-Reftype: branch X-Git-Commit: 762729bdd4d3dd350de4dc2339d38c21cad68f25 Auto-Submitted: auto-generated Date: Thu, 05 Feb 2026 15:26:55 +0000 Message-Id: <6984b6bf.1808f.3c065e9a@gitrepo.freebsd.org> The branch stable/15 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=762729bdd4d3dd350de4dc2339d38c21cad68f25 commit 762729bdd4d3dd350de4dc2339d38c21cad68f25 Author: Dag-Erling Smørgrav AuthorDate: 2026-02-02 15:46:53 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-02-05 14:50:19 +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 6015114d6c47..73070d171cd1 100644 --- a/lib/libc/gen/closedir.c +++ b/lib/libc/gen/closedir.c @@ -68,6 +68,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 263dfdd6eb95..ccbc60b03776 100644 --- a/lib/libc/gen/directory.3 +++ b/lib/libc/gen/directory.3 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd August 1, 2020 +.Dd January 31, 2026 .Dt DIRECTORY 3 .Os .Sh NAME @@ -86,13 +86,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 @@ -134,14 +127,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 @@ -166,10 +151,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 @@ -179,12 +160,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 @@ -217,28 +195,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 @@ -255,6 +227,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 08d9eb10eaa2..4c08b7156055 100644 --- a/lib/libc/gen/opendir.c +++ b/lib/libc/gen/opendir.c @@ -42,6 +42,5 @@ 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 c5c2e662efd8..321cb2261b8c 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 df829e98d138..5cead2adc6d4 100644 --- a/lib/libc/gen/rewinddir.c +++ b/lib/libc/gen/rewinddir.c @@ -43,7 +43,6 @@ 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 fb589f4b36b6..84b20fbafa03 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -232,14 +232,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 1731cc4d7a2c..d71b7bed158c 100644 --- a/lib/libc/gen/telldir.c +++ b/lib/libc/gen/telldir.c @@ -53,7 +53,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 @@ -95,7 +95,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. */