mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-14 20:37:06 +00:00
libc: split scandir() into scandir_dirp() and proper scandir()
(cherry picked from commit cb6e97f4da
)
This commit is contained in:
parent
628b801a8d
commit
066b09c2b1
|
@ -64,22 +64,18 @@ typedef DECLARE_BLOCK(int, dcomp_block, const struct dirent **,
|
|||
static int alphasort_thunk(void *thunk, const void *p1, const void *p2);
|
||||
#endif
|
||||
|
||||
int
|
||||
static int
|
||||
#ifdef I_AM_SCANDIR_B
|
||||
scandir_b(const char *dirname, struct dirent ***namelist, select_block select,
|
||||
scandir_b_dirp(DIR *dirp, struct dirent ***namelist, select_block select,
|
||||
dcomp_block dcomp)
|
||||
#else
|
||||
scandir(const char *dirname, struct dirent ***namelist,
|
||||
scandir_dirp(DIR *dirp, struct dirent ***namelist,
|
||||
int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **,
|
||||
const struct dirent **))
|
||||
const struct dirent **))
|
||||
#endif
|
||||
{
|
||||
struct dirent *d, *p, **names = NULL;
|
||||
size_t arraysz, numitems;
|
||||
DIR *dirp;
|
||||
|
||||
if ((dirp = opendir(dirname)) == NULL)
|
||||
return(-1);
|
||||
|
||||
numitems = 0;
|
||||
arraysz = 32; /* initial estimate of the array size */
|
||||
|
@ -138,6 +134,30 @@ scandir(const char *dirname, struct dirent ***namelist,
|
|||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
#ifdef I_AM_SCANDIR_B
|
||||
scandir_b(const char *dirname, struct dirent ***namelist, select_block select,
|
||||
dcomp_block dcomp)
|
||||
#else
|
||||
scandir(const char *dirname, struct dirent ***namelist,
|
||||
int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **,
|
||||
const struct dirent **))
|
||||
#endif
|
||||
{
|
||||
DIR *dirp;
|
||||
|
||||
dirp = opendir(dirname);
|
||||
if (dirp == NULL)
|
||||
return (-1);
|
||||
return (
|
||||
#ifdef I_AM_SCANDIR_B
|
||||
scandir_b_dirp
|
||||
#else
|
||||
scandir_dirp
|
||||
#endif
|
||||
(dirp, namelist, select, dcomp));
|
||||
}
|
||||
|
||||
#ifndef I_AM_SCANDIR_B
|
||||
/*
|
||||
* Alphabetic order comparison routine for those who want it.
|
||||
|
|
Loading…
Reference in a new issue