Commit | Line | Data |
---|---|---|
34e8f829 A |
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" | |
5 | ||
6 | /* | |
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. | |
12 | */ | |
13 | -#undef DIRSIZ | |
14 | -#define DIRSIZ(dp) \ | |
15 | - ((sizeof(struct dirent) - sizeof(dp)->d_name) + \ | |
16 | - (((dp)->d_namlen + 1 + 3) &~ 3)) | |
17 | ||
18 | int | |
19 | -scandir(dirname, namelist, select, dcomp) | |
20 | +scandir_b(dirname, namelist, select, dcomp) | |
21 | const char *dirname; | |
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 *); | |
27 | { | |
28 | struct dirent *d, *p, **names = NULL; | |
29 | size_t nitems = 0; | |
30 | @@ -91,12 +87,12 @@ scandir(dirname, namelist, select, dcomp | |
31 | goto fail; | |
32 | ||
33 | while ((d = readdir(dirp)) != NULL) { | |
34 | - if (select != NULL && !(*select)(d)) | |
35 | + if (select != NULL && !select(d)) | |
36 | continue; /* just selected names */ | |
37 | /* | |
38 | * Make a minimum size copy of the data | |
39 | */ | |
40 | - p = (struct dirent *)malloc(DIRSIZ(d)); | |
41 | + p = (struct dirent *)malloc(_GENERIC_DIRSIZ(d)); | |
42 | if (p == NULL) | |
43 | goto fail; | |
44 | p->d_fileno = d->d_fileno; | |
45 | @@ -125,7 +121,7 @@ scandir(dirname, namelist, select, dcomp | |
46 | } | |
47 | closedir(dirp); | |
48 | if (nitems && dcomp != NULL) | |
49 | - qsort(names, nitems, sizeof(struct dirent *), dcomp); | |
50 | + qsort_b(names, nitems, sizeof(struct dirent *), dcomp); | |
51 | *namelist = names; | |
52 | return(nitems); | |
53 | ||
54 | @@ -136,15 +132,3 @@ fail: | |
55 | closedir(dirp); | |
56 | return -1; | |
57 | } | |
58 | - | |
59 | -/* | |
60 | - * Alphabetic order comparison routine for those who want it. | |
61 | - */ | |
62 | -int | |
63 | -alphasort(d1, d2) | |
64 | - const void *d1; | |
65 | - const void *d2; | |
66 | -{ | |
67 | - return(strcmp((*(struct dirent **)d1)->d_name, | |
68 | - (*(struct dirent **)d2)->d_name)); | |
69 | -} |