Merge "scandir: clarity improvements." am: 9dfcaa64e8 am: 7168ca2986 am: 664ce27366

Original change: https://android-review.googlesource.com/c/platform/bionic/+/2512139

Change-Id: I24a2f32d678d0a981f7312dec47b980003b6bc2c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Elliott Hughes 2023-03-30 19:17:49 +00:00 committed by Automerger Merge Worker
commit 83aa8dff1f

View file

@ -69,11 +69,8 @@ class ScandirResult {
}
void Sort(int (*comparator)(const dirent**, const dirent**)) {
// If we have entries and a comparator, sort them.
if (size_ > 0 && comparator != nullptr) {
qsort(names_, size_, sizeof(dirent*),
reinterpret_cast<int (*)(const void*, const void*)>(comparator));
}
qsort(names_, size_, sizeof(dirent*),
reinterpret_cast<int (*)(const void*, const void*)>(comparator));
}
private:
@ -120,7 +117,9 @@ int scandirat(int parent_fd, const char* dir_name, dirent*** name_list,
names.Add(entry);
}
names.Sort(comparator);
if (comparator != nullptr) {
names.Sort(comparator);
}
size_t size = names.size();
*name_list = names.release();