Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libc/gen/scandir.c
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
qsort_b(void *, size_t, size_t, void*); | qsort_b(void *, size_t, size_t, void*); | ||||
#endif | #endif | ||||
#else | #else | ||||
#define SELECT(x) select(x) | #define SELECT(x) select(x) | ||||
#endif | #endif | ||||
static int alphasort_thunk(void *thunk, const void *p1, const void *p2); | static int alphasort_thunk(void *thunk, const void *p1, const void *p2); | ||||
/* | |||||
* The 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 | int | ||||
#ifdef I_AM_SCANDIR_B | #ifdef I_AM_SCANDIR_B | ||||
scandir_b(const char *dirname, struct dirent ***namelist, | scandir_b(const char *dirname, struct dirent ***namelist, | ||||
DECLARE_BLOCK(int, select, const struct dirent *), | DECLARE_BLOCK(int, select, const struct dirent *), | ||||
DECLARE_BLOCK(int, dcomp, const struct dirent **, const struct dirent **)) | DECLARE_BLOCK(int, dcomp, const struct dirent **, const struct dirent **)) | ||||
#else | #else | ||||
scandir(const char *dirname, struct dirent ***namelist, | scandir(const char *dirname, struct dirent ***namelist, | ||||
int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **, | int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **, | ||||
Show All 14 Lines | if (names == NULL) | ||||
goto fail; | goto fail; | ||||
while ((d = readdir(dirp)) != NULL) { | while ((d = readdir(dirp)) != NULL) { | ||||
if (select != NULL && !SELECT(d)) | if (select != NULL && !SELECT(d)) | ||||
continue; /* just selected names */ | continue; /* just selected names */ | ||||
/* | /* | ||||
* Make a minimum size copy of the data | * Make a minimum size copy of the data | ||||
*/ | */ | ||||
p = (struct dirent *)malloc(DIRSIZ(d)); | p = (struct dirent *)malloc(_GENERIC_DIRSIZ(d)); | ||||
if (p == NULL) | if (p == NULL) | ||||
goto fail; | goto fail; | ||||
p->d_fileno = d->d_fileno; | p->d_fileno = d->d_fileno; | ||||
p->d_type = d->d_type; | p->d_type = d->d_type; | ||||
p->d_reclen = d->d_reclen; | p->d_reclen = d->d_reclen; | ||||
p->d_namlen = d->d_namlen; | p->d_namlen = d->d_namlen; | ||||
bcopy(d->d_name, p->d_name, p->d_namlen + 1); | bcopy(d->d_name, p->d_name, p->d_namlen + 1); | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |