libc: Fix alphasort() signature (and implementation).
The declaration for alphasort() in <dirent.h> used the deprecated:
int alphasort(const void*, const void*);
while both Posix and GLibc use instead:
int alphasort(const struct dirent** a, const struct dirent** b);
See: http://pubs.opengroup.org/onlinepubs/9699919799/functions/alphasort.html
This patch does the following:
- Update the declaration to match Posix/GLibc
- Get rid of the upstream BSD code which isn't compatible with the new
signature.
- Implement a new trivial alphasort() with the right signature, and
ensure that it uses strcoll() instead of strcmp().
- Remove Bionic-specific #ifdef .. #else .. #endif block in
dirent_test.cpp which uses alphasort().
Even through strcoll() currently uses strcmp(), this does the right
thing in the case where we decide to update strcoll() to properly
implement locale-specific ordered comparison.
Change-Id: I4fd45604d8a940aaf2eb0ecd7d73e2f11c9bca96
diff --git a/libc/bionic/opendir.cpp b/libc/bionic/dirent.cpp
similarity index 97%
rename from libc/bionic/opendir.cpp
rename to libc/bionic/dirent.cpp
index cd5b221..3a7b5b4 100644
--- a/libc/bionic/opendir.cpp
+++ b/libc/bionic/dirent.cpp
@@ -190,3 +190,7 @@
*namelist = de_list;
return n_elem;
}
+
+int alphasort(const struct dirent** a, const struct dirent** b) {
+ return strcoll((*a)->d_name, (*b)->d_name);
+}