Merge "scandir: clarity improvements."

This commit is contained in:
Elliott Hughes 2023-03-29 21:07:25 +00:00 committed by Gerrit Code Review
commit 9dfcaa64e8

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();