1 --- scandir_b.c.orig 2008-07-29 12:03:05.000000000 -0700
2 +++ scandir_b.c 2008-07-29 12:03:31.000000000 -0700
3 @@ -53,22 +53,18 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/sca
4 #include "un-namespace.h"
7 - * The DIRSIZ macro is the minimum record length which will hold the directory
8 + * The _GENERIC_DIRSIZ macro is the minimum record length which will hold the directory
9 * entry. This requires the amount of space in struct dirent without the
10 * d_name field, plus enough space for the name and a terminating nul byte
11 * (dp->d_namlen + 1), rounded up to a 4 byte boundary.
15 - ((sizeof(struct dirent) - sizeof(dp)->d_name) + \
16 - (((dp)->d_namlen + 1 + 3) &~ 3))
19 -scandir(dirname, namelist, select, dcomp)
20 +scandir_b(dirname, namelist, select, dcomp)
22 struct dirent ***namelist;
23 - int (*select)(struct dirent *);
24 - int (*dcomp)(const void *, const void *);
25 + int (^select)(struct dirent *);
26 + int (^dcomp)(const void *, const void *);
28 struct dirent *d, *p, **names = NULL;
30 @@ -91,12 +87,12 @@ scandir(dirname, namelist, select, dcomp
33 while ((d = readdir(dirp)) != NULL) {
34 - if (select != NULL && !(*select)(d))
35 + if (select != NULL && !select(d))
36 continue; /* just selected names */
38 * Make a minimum size copy of the data
40 - p = (struct dirent *)malloc(DIRSIZ(d));
41 + p = (struct dirent *)malloc(_GENERIC_DIRSIZ(d));
44 p->d_fileno = d->d_fileno;
45 @@ -125,7 +121,7 @@ scandir(dirname, namelist, select, dcomp
48 if (nitems && dcomp != NULL)
49 - qsort(names, nitems, sizeof(struct dirent *), dcomp);
50 + qsort_b(names, nitems, sizeof(struct dirent *), dcomp);
54 @@ -136,15 +132,3 @@ fail:
60 - * Alphabetic order comparison routine for those who want it.
67 - return(strcmp((*(struct dirent **)d1)->d_name,
68 - (*(struct dirent **)d2)->d_name));