Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 12 Mar 2017 03:22:18 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r315095 - head/lib/libc/gen
Message-ID:  <201703120322.v2C3MIxW016364@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703120322.v2C3MIxW016364>