aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Waychison <mikew@google.com>2011-08-02 15:46:55 -0700
committermaximilian attems <max@stro.at>2011-08-03 10:18:38 +0200
commite90b19b9558c9a5a054266393b7ef378b133f1aa (patch)
treed477a85409c5165fc2dcd1abc880b0d444d84273
parent6a36efee1559964d0aaa7e8073c0472e956b202b (diff)
downloadklibc-e90b19b9558c9a5a054266393b7ef378b133f1aa.tar.gz
[klibc] Add alphasort() support.
Add support for alphasort() as defined in POSIX.1-2008. Signed-off-by: Mike Waychison <mikew@google.com> Reviewed-by: H. Peter Anvin <hpa@zytor.com> Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r--usr/include/dirent.h2
-rw-r--r--usr/klibc/Kbuild2
-rw-r--r--usr/klibc/alphasort.c12
3 files changed, 15 insertions, 1 deletions
diff --git a/usr/include/dirent.h b/usr/include/dirent.h
index 0bcf40bbf1177..725452e45ee5e 100644
--- a/usr/include/dirent.h
+++ b/usr/include/dirent.h
@@ -35,4 +35,6 @@ __extern int scandir(const char *, struct dirent ***,
int (*)(const struct dirent **,
const struct dirent **));
+__extern int alphasort(const struct dirent **, const struct dirent **);
+
#endif /* _DIRENT_H */
diff --git a/usr/klibc/Kbuild b/usr/klibc/Kbuild
index 40e61da5da1cb..c4f9ae250e489 100644
--- a/usr/klibc/Kbuild
+++ b/usr/klibc/Kbuild
@@ -42,7 +42,7 @@ klib-y := vsnprintf.o snprintf.o vsprintf.o sprintf.o \
seteuid.o setegid.o \
getenv.o setenv.o putenv.o __put_env.o unsetenv.o \
clearenv.o nullenv.o \
- getopt.o getopt_long.o readdir.o scandir.o remove.o \
+ getopt.o getopt_long.o readdir.o scandir.o alphasort.o remove.o \
syslog.o closelog.o pty.o getpt.o posix_openpt.o isatty.o reboot.o \
time.o utime.o llseek.o nice.o getpriority.o \
qsort.o bsearch.o \
diff --git a/usr/klibc/alphasort.c b/usr/klibc/alphasort.c
new file mode 100644
index 0000000000000..d420495cbde1b
--- /dev/null
+++ b/usr/klibc/alphasort.c
@@ -0,0 +1,12 @@
+/*
+ * alphasort.c: alphasort
+ */
+
+#include <string.h>
+
+#include <dirent.h>
+
+int alphasort(const struct dirent **a, const struct dirent **b)
+{
+ return strcmp((*a)->d_name, (*b)->d_name);
+}