|
@@ -53,10 +53,7 @@ int scandir(const char *dir, struct dirent ***namelist,
|
|
|
|
|
|
names = malloc(sizeof (struct dirent *) * count);
|
|
names = malloc(sizeof (struct dirent *) * count);
|
|
|
|
|
|
- closedir(d);
|
|
+ rewinddir(d);
|
|
- d = opendir(dir);
|
|
|
|
- if (NULL == d)
|
|
|
|
- return -1;
|
|
|
|
|
|
|
|
while (NULL != (current = readdir(d))) {
|
|
while (NULL != (current = readdir(d))) {
|
|
if (NULL == selector || selector(current)) {
|
|
if (NULL == selector || selector(current)) {
|
|
@@ -73,6 +70,10 @@ int scandir(const char *dir, struct dirent ***namelist,
|
|
if (pos != count)
|
|
if (pos != count)
|
|
names = realloc(names, sizeof (struct dirent *) * pos);
|
|
names = realloc(names, sizeof (struct dirent *) * pos);
|
|
|
|
|
|
|
|
+ if (compar != NULL) {
|
|
|
|
+ qsort(names, pos, sizeof (struct dirent *), compar);
|
|
|
|
+ }
|
|
|
|
+
|
|
*namelist = names;
|
|
*namelist = names;
|
|
|
|
|
|
return pos;
|
|
return pos;
|