From 099c1958f371a3c67eaa74c83af6b97080ff1c0c Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Tue, 8 May 2001 18:06:08 +0000 Subject: A patch from Jon Nelson to make scandir sort things as it is supposed to do. --- libc/misc/dirent/scandir.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'libc/misc/dirent/scandir.c') 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; -- cgit v1.2.3