mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/2] glob: Add sorted output support
Date: Mon, 14 May 2012 20:21:00 +0200	[thread overview]
Message-ID: <1337019660-12096-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1337019660-12096-1-git-send-email-s.hauer@pengutronix.de>

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

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/Kconfig |    8 +++++++-
 lib/glob.c     |   11 +++++------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index 81e3acb..9f0e0f8 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -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
diff --git a/lib/glob.c b/lib/glob.c
index 74d2b12..c4c6067 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -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:
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      parent reply	other threads:[~2012-05-14 18:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-14 18:20 [PATCH] Add glob sort support Sascha Hauer
2012-05-14 18:20 ` [PATCH 1/2] add qsort support Sascha Hauer
2012-05-14 18:21 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1337019660-12096-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox