9
0
Fork 0

glob: Add sorted output support

This allows us for example to execute init scripts in the correct
order.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2012-05-13 15:03:08 +02:00
parent cbdf1e6dfa
commit 91c38de28f
2 changed files with 12 additions and 7 deletions

View File

@ -310,7 +310,13 @@ config GLOB
depends on SHELL_HUSH
help
If you want to use wildcards like * or ? say y here.
config GLOB_SORT
select QSORT
bool
prompt "glob sort support"
depends on GLOB
config PROMPT_HUSH_PS2
string
depends on SHELL_HUSH

View File

@ -22,6 +22,7 @@ Cambridge, MA 02139, USA. */
#include <malloc.h>
#include <xfuncs.h>
#include <fnmatch.h>
#include <qsort.h>
#define _GNU_SOURCE
#include <glob.h>
@ -75,12 +76,10 @@ int glob_pattern_p(const char *pattern, int quote)
#ifdef CONFIG_GLOB_SORT
/* Do a collated comparison of A and B. */
static int collated_compare(a, b)
const __ptr_t a;
const __ptr_t b;
static int collated_compare(const void *a, const void *b)
{
const char *const s1 = *(const char *const *)a;
const char *const s2 = *(const char *const *)b;
const char *s1 = a;
const char *s2 = b;
if (s1 == s2)
return 0;
@ -266,7 +265,7 @@ int glob(const char *pattern, int flags,
/* Sort the vector. */
qsort((__ptr_t) & pglob->gl_pathv[oldcount],
pglob->gl_pathc - oldcount,
sizeof(char *), (__compar_fn_t) collated_compare);
sizeof(char *), collated_compare);
#endif
status = 0;
out: