From 9bd82e1d803b9d6d92d70b2fc204aa55f4084ce8 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 22 Jun 2013 00:30:45 +0200 Subject: [PATCH] Add alphasort(3). --- libc/Makefile | 1 + libc/dirent/alphasort.cpp | 31 +++++++++++++++++++++++++++++++ libc/include/dirent.h | 1 + 3 files changed, 33 insertions(+) create mode 100644 libc/dirent/alphasort.cpp 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);