fix: removed dirent unused function
This commit is contained in:
@@ -449,28 +449,6 @@ _wopendir(
|
|||||||
return dirp;
|
return dirp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Read next directory entry.
|
|
||||||
*
|
|
||||||
* Returns pointer to static directory entry which may be overwritten by
|
|
||||||
* subsequent calls to _wreaddir().
|
|
||||||
*/
|
|
||||||
static struct _wdirent*
|
|
||||||
_wreaddir(
|
|
||||||
_WDIR *dirp)
|
|
||||||
{
|
|
||||||
struct _wdirent *entry;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Read directory entry to buffer. We can safely ignore the return value
|
|
||||||
* as entry will be set to NULL in case of error.
|
|
||||||
*/
|
|
||||||
(void) _wreaddir_r (dirp, &dirp->ent, &entry);
|
|
||||||
|
|
||||||
/* Return pointer to statically allocated directory entry */
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read next directory entry.
|
* Read next directory entry.
|
||||||
*
|
*
|
||||||
@@ -858,158 +836,6 @@ closedir(
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Rewind directory stream to beginning.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
rewinddir(
|
|
||||||
DIR* dirp)
|
|
||||||
{
|
|
||||||
/* Rewind wide-character string directory stream */
|
|
||||||
_wrewinddir (dirp->wdirp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Scan directory for entries.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
scandir(
|
|
||||||
const char *dirname,
|
|
||||||
struct dirent ***namelist,
|
|
||||||
int (*filter)(const struct dirent*),
|
|
||||||
int (*compare)(const struct dirent**, const struct dirent**))
|
|
||||||
{
|
|
||||||
struct dirent **files = NULL;
|
|
||||||
size_t size = 0;
|
|
||||||
size_t allocated = 0;
|
|
||||||
const size_t init_size = 1;
|
|
||||||
DIR *dir = NULL;
|
|
||||||
struct dirent *entry;
|
|
||||||
struct dirent *tmp = NULL;
|
|
||||||
size_t i;
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
/* Open directory stream */
|
|
||||||
dir = opendir (dirname);
|
|
||||||
if (dir) {
|
|
||||||
|
|
||||||
/* Read directory entries to memory */
|
|
||||||
while (1) {
|
|
||||||
|
|
||||||
/* Enlarge pointer table to make room for another pointer */
|
|
||||||
if (size >= allocated) {
|
|
||||||
void *p;
|
|
||||||
size_t num_entries;
|
|
||||||
|
|
||||||
/* Compute number of entries in the enlarged pointer table */
|
|
||||||
if (size < init_size) {
|
|
||||||
/* Allocate initial pointer table */
|
|
||||||
num_entries = init_size;
|
|
||||||
} else {
|
|
||||||
/* Double the size */
|
|
||||||
num_entries = size * 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocate first pointer table or enlarge existing table */
|
|
||||||
p = realloc (files, sizeof (void*) * num_entries);
|
|
||||||
if (p != NULL) {
|
|
||||||
/* Got the memory */
|
|
||||||
files = (dirent**) p;
|
|
||||||
allocated = num_entries;
|
|
||||||
} else {
|
|
||||||
/* Out of memory */
|
|
||||||
result = -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocate room for temporary directory entry */
|
|
||||||
if (tmp == NULL) {
|
|
||||||
tmp = (struct dirent*) malloc (sizeof (struct dirent));
|
|
||||||
if (tmp == NULL) {
|
|
||||||
/* Cannot allocate temporary directory entry */
|
|
||||||
result = -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read directory entry to temporary area */
|
|
||||||
if (readdir_r (dir, tmp, &entry) == /*OK*/0) {
|
|
||||||
|
|
||||||
/* Did we get an entry? */
|
|
||||||
if (entry != NULL) {
|
|
||||||
int pass;
|
|
||||||
|
|
||||||
/* Determine whether to include the entry in result */
|
|
||||||
if (filter) {
|
|
||||||
/* Let the filter function decide */
|
|
||||||
pass = filter (tmp);
|
|
||||||
} else {
|
|
||||||
/* No filter function, include everything */
|
|
||||||
pass = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pass) {
|
|
||||||
/* Store the temporary entry to pointer table */
|
|
||||||
files[size++] = tmp;
|
|
||||||
tmp = NULL;
|
|
||||||
|
|
||||||
/* Keep up with the number of files */
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* End of directory stream reached => sort entries and
|
|
||||||
* exit.
|
|
||||||
*/
|
|
||||||
qsort (files, size, sizeof (void*),
|
|
||||||
(int (*) (const void*, const void*)) compare);
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
/* Error reading directory entry */
|
|
||||||
result = /*Error*/ -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
/* Cannot open directory */
|
|
||||||
result = /*Error*/ -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Release temporary directory entry */
|
|
||||||
if (tmp) {
|
|
||||||
free (tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Release allocated memory on error */
|
|
||||||
if (result < 0) {
|
|
||||||
for (i = 0; i < size; i++) {
|
|
||||||
free (files[i]);
|
|
||||||
}
|
|
||||||
free (files);
|
|
||||||
files = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close directory stream */
|
|
||||||
if (dir) {
|
|
||||||
closedir (dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Pass pointer table to caller */
|
|
||||||
if (namelist) {
|
|
||||||
*namelist = files;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Alphabetical sorting */
|
/* Alphabetical sorting */
|
||||||
static int
|
static int
|
||||||
alphasort(
|
alphasort(
|
||||||
@@ -1018,16 +844,6 @@ alphasort(
|
|||||||
return strcoll ((*a)->d_name, (*b)->d_name);
|
return strcoll ((*a)->d_name, (*b)->d_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sort versions */
|
|
||||||
static int
|
|
||||||
versionsort(
|
|
||||||
const struct dirent **a, const struct dirent **b)
|
|
||||||
{
|
|
||||||
/* FIXME: implement strverscmp and use that */
|
|
||||||
return alphasort (a, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Convert multi-byte string to wide character string */
|
/* Convert multi-byte string to wide character string */
|
||||||
static int
|
static int
|
||||||
dirent_mbstowcs_s(
|
dirent_mbstowcs_s(
|
||||||
|
|||||||
Reference in New Issue
Block a user