diff options
Diffstat (limited to 'libc')
-rw-r--r-- | libc/misc/dirent/scandir.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/libc/misc/dirent/scandir.c b/libc/misc/dirent/scandir.c index 2b07e294c..31ebce549 100644 --- a/libc/misc/dirent/scandir.c +++ b/libc/misc/dirent/scandir.c @@ -53,10 +53,7 @@ int scandir(const char *dir, struct dirent ***namelist, names = malloc(sizeof (struct dirent *) * count); - closedir(d); - d = opendir(dir); - if (NULL == d) - return -1; + rewinddir(d); while (NULL != (current = readdir(d))) { if (NULL == selector || selector(current)) { @@ -73,6 +70,10 @@ int scandir(const char *dir, struct dirent ***namelist, if (pos != count) names = realloc(names, sizeof (struct dirent *) * pos); + if (compar != NULL) { + qsort(names, pos, sizeof (struct dirent *), compar); + } + *namelist = names; return pos; |