diff --git a/libc/Makefile b/libc/Makefile
index 6de9caf8..cd2b4fe2 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -29,6 +29,7 @@ calloc.o \
clearerr.o \
c++.o \
ctype.o \
+dirent/alphasort.o \
dirent/dir.o \
div.o \
errno.o \
diff --git a/libc/dirent/alphasort.cpp b/libc/dirent/alphasort.cpp
new file mode 100644
index 00000000..f2203b5f
--- /dev/null
+++ b/libc/dirent/alphasort.cpp
@@ -0,0 +1,31 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2013.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ dirent/alphasort.cpp
+ Compare directory entries alphabetically.
+
+*******************************************************************************/
+
+#include
+#include
+
+extern "C" int alphasort(const struct dirent** a, const struct dirent** b)
+{
+ return strcoll((*a)->d_name, (*b)->d_name);
+}
diff --git a/libc/include/dirent.h b/libc/include/dirent.h
index d52002fe..d1290766 100644
--- a/libc/include/dirent.h
+++ b/libc/include/dirent.h
@@ -40,6 +40,7 @@ struct dirent
char d_name[0];
};
+int alphasort(const struct dirent**, const struct dirent**);
int closedir(DIR* dir);
int dirfd(DIR* dir);
DIR* fdopendir(int fd);