aboutsummaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2025-06-26 07:37:06 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2026-02-05 14:47:46 +0000
commitd2f8f53385b3f2b42e38c387cb1ccba4518167e9 (patch)
tree44e94d29dcf100dbccded6c42af533ec49854874 /lib/libc
parent1a3c32bac0f029b0186bb856373fe3bcd2d5e18f (diff)
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/scandir.c24
1 files 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;