summaryrefslogtreecommitdiff
path: root/libc/misc/dirent
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-05-08 18:06:08 +0000
committerEric Andersen <andersen@codepoet.org>2001-05-08 18:06:08 +0000
commit099c1958f371a3c67eaa74c83af6b97080ff1c0c (patch)
tree74a3d00ee17e52af1c4b413c35c86d4a7b805e38 /libc/misc/dirent
parentf8a65069905b067fda10667f4275c9f3ead64eed (diff)
A patch from Jon Nelson <jnelson@securepipe.com> to make scandir
sort things as it is supposed to do.
Diffstat (limited to 'libc/misc/dirent')
-rw-r--r--libc/misc/dirent/scandir.c9
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;