Date: Thu, 05 Feb 2026 15:27:28 +0000 From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: d2f8f53385b3 - stable/14 - scandir: Code cleanup. Message-ID: <6984b6e0.18a84.1b018149@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=d2f8f53385b3f2b42e38c387cb1ccba4518167e9 commit d2f8f53385b3f2b42e38c387cb1ccba4518167e9 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2025-06-26 07:37:06 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2026-02-05 14:47:46 +0000 scandir: Code cleanup. Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D51050 (cherry picked from commit 8ebc0768663b0ea9f78a0b8cffb93ee1684a9b08) --- lib/libc/gen/scandir.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c index 4d1ccab14f91..3f13248a3f2b 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -71,8 +71,8 @@ scandir_dirp_b(DIR *dirp, struct dirent ***namelist, select_block select, dcomp_block dcomp) #else scandir_dirp(DIR *dirp, struct dirent ***namelist, - int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **, - const struct dirent **)) + int (*select)(const struct dirent *), + int (*dcomp)(const struct dirent **, const struct dirent **)) #endif { struct dirent *d, *p = NULL, **names = NULL, **names2; @@ -102,7 +102,7 @@ scandir_dirp(DIR *dirp, struct dirent ***namelist, * realloc the maximum size. */ if (numitems >= arraysz) { - arraysz = arraysz ? arraysz * 2 : 32; + arraysz = arraysz * 2; names2 = reallocarray(names, arraysz, sizeof(*names)); if (names2 == NULL) goto fail; @@ -117,13 +117,15 @@ scandir_dirp(DIR *dirp, struct dirent ***namelist, */ if (errno != 0) goto fail; - if (numitems && dcomp != NULL) + if (numitems > 0 && dcomp != NULL) { #ifdef I_AM_SCANDIR_B - qsort_b(names, numitems, sizeof(struct dirent *), (void*)dcomp); + qsort_b(names, numitems, sizeof(struct dirent *), + (void *)dcomp); #else qsort_r(names, numitems, sizeof(struct dirent *), scandir_thunk_cmp, &dcomp); #endif + } *namelist = names; return (numitems); @@ -144,8 +146,8 @@ scandir_b(const char *dirname, struct dirent ***namelist, select_block select, dcomp_block dcomp) #else scandir(const char *dirname, struct dirent ***namelist, - int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **, - const struct dirent **)) + int (*select)(const struct dirent *), + int (*dcomp)(const struct dirent **, const struct dirent **)) #endif { DIR *dirp; @@ -173,8 +175,8 @@ fdscandir_b(int dirfd, struct dirent ***namelist, select_block select, dcomp_block dcomp) #else fdscandir(int dirfd, struct dirent ***namelist, - int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **, - const struct dirent **)) + int (*select)(const struct dirent *), + int (*dcomp)(const struct dirent **, const struct dirent **)) #endif { DIR *dirp; @@ -202,8 +204,8 @@ scandirat_b(int dirfd, const char *dirname, struct dirent ***namelist, select_block select, dcomp_block dcomp) #else scandirat(int dirfd, const char *dirname, struct dirent ***namelist, - int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **, - const struct dirent **)) + int (*select)(const struct dirent *), + int (*dcomp)(const struct dirent **, const struct dirent **)) #endif { int fd, ret, serrno;home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6984b6e0.18a84.1b018149>
