svn commit: r315095 - head/lib/libc/gen
Pedro F. Giffuni
pfg at FreeBSD.org
Sun Mar 12 03:22:19 UTC 2017
Author: pfg
Date: Sun Mar 12 03:22:18 2017
New Revision: 315095
URL: https://svnweb.freebsd.org/changeset/base/315095
Log:
libc: small cleanups.
Rename nitems to numitems: it shares the anme with an existing macro in
sys/params.h. Also initialize the value later which avoids asigning the
value if we exit early.
Reviewed by: ngie
MFC after: 3 days
Modified:
head/lib/libc/gen/scandir.c
Modified: head/lib/libc/gen/scandir.c
==============================================================================
--- head/lib/libc/gen/scandir.c Sun Mar 12 02:21:16 2017 (r315094)
+++ head/lib/libc/gen/scandir.c Sun Mar 12 03:22:18 2017 (r315095)
@@ -82,7 +82,7 @@ scandir(const char *dirname, struct dire
#endif
{
struct dirent *d, *p, **names = NULL;
- size_t nitems = 0;
+ size_t numitems;
long arraysz;
DIR *dirp;
@@ -94,6 +94,7 @@ scandir(const char *dirname, struct dire
if (names == NULL)
goto fail;
+ numitems = 0;
while ((d = readdir(dirp)) != NULL) {
if (select != NULL && !SELECT(d))
continue; /* just selected names */
@@ -112,7 +113,7 @@ scandir(const char *dirname, struct dire
* Check to make sure the array has space left and
* realloc the maximum size.
*/
- if (nitems >= arraysz) {
+ if (numitems >= arraysz) {
struct dirent **names2;
names2 = (struct dirent **)realloc((char *)names,
@@ -124,22 +125,22 @@ scandir(const char *dirname, struct dire
names = names2;
arraysz *= 2;
}
- names[nitems++] = p;
+ names[numitems++] = p;
}
closedir(dirp);
- if (nitems && dcomp != NULL)
+ if (numitems && dcomp != NULL)
#ifdef I_AM_SCANDIR_B
- qsort_b(names, nitems, sizeof(struct dirent *), (void*)dcomp);
+ qsort_b(names, numitems, sizeof(struct dirent *), (void*)dcomp);
#else
- qsort_r(names, nitems, sizeof(struct dirent *),
+ qsort_r(names, numitems, sizeof(struct dirent *),
&dcomp, alphasort_thunk);
#endif
*namelist = names;
- return (nitems);
+ return (numitems);
fail:
- while (nitems > 0)
- free(names[--nitems]);
+ while (numitems > 0)
+ free(names[--numitems]);
free(names);
closedir(dirp);
return (-1);
More information about the svn-src-all
mailing list