scandir_b.c.patch   [plain text]


--- scandir_b.c.orig	2008-07-29 12:03:05.000000000 -0700
+++ scandir_b.c	2008-07-29 12:03:31.000000000 -0700
@@ -53,22 +53,18 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/sca
 #include "un-namespace.h"
 
 /*
- * The DIRSIZ macro is the minimum record length which will hold the directory
+ * The _GENERIC_DIRSIZ macro is the minimum record length which will hold the directory
  * entry.  This requires the amount of space in struct dirent without the
  * d_name field, plus enough space for the name and a terminating nul byte
  * (dp->d_namlen + 1), rounded up to a 4 byte boundary.
  */
-#undef DIRSIZ
-#define DIRSIZ(dp)							\
-	((sizeof(struct dirent) - sizeof(dp)->d_name) +			\
-	    (((dp)->d_namlen + 1 + 3) &~ 3))
 
 int
-scandir(dirname, namelist, select, dcomp)
+scandir_b(dirname, namelist, select, dcomp)
 	const char *dirname;
 	struct dirent ***namelist;
-	int (*select)(struct dirent *);
-	int (*dcomp)(const void *, const void *);
+	int (^select)(struct dirent *);
+	int (^dcomp)(const void *, const void *);
 {
 	struct dirent *d, *p, **names = NULL;
 	size_t nitems = 0;
@@ -91,12 +87,12 @@ scandir(dirname, namelist, select, dcomp
 		goto fail;
 
 	while ((d = readdir(dirp)) != NULL) {
-		if (select != NULL && !(*select)(d))
+		if (select != NULL && !select(d))
 			continue;	/* just selected names */
 		/*
 		 * Make a minimum size copy of the data
 		 */
-		p = (struct dirent *)malloc(DIRSIZ(d));
+		p = (struct dirent *)malloc(_GENERIC_DIRSIZ(d));
 		if (p == NULL)
 			goto fail;
 		p->d_fileno = d->d_fileno;
@@ -125,7 +121,7 @@ scandir(dirname, namelist, select, dcomp
 	}
 	closedir(dirp);
 	if (nitems && dcomp != NULL)
-		qsort(names, nitems, sizeof(struct dirent *), dcomp);
+		qsort_b(names, nitems, sizeof(struct dirent *), dcomp);
 	*namelist = names;
 	return(nitems);
 
@@ -136,15 +132,3 @@ fail:
 	closedir(dirp);
 	return -1;
 }
-
-/*
- * Alphabetic order comparison routine for those who want it.
- */
-int
-alphasort(d1, d2)
-	const void *d1;
-	const void *d2;
-{
-	return(strcmp((*(struct dirent **)d1)->d_name,
-	    (*(struct dirent **)d2)->d_name));
-}