From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from metis.ext.pengutronix.de ([2001:6f8:1178:4:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wk68E-0006xV-6A for barebox@lists.infradead.org; Tue, 13 May 2014 06:24:08 +0000 From: Sascha Hauer Date: Tue, 13 May 2014 08:23:40 +0200 Message-Id: <1399962220-27617-2-git-send-email-s.hauer@pengutronix.de> In-Reply-To: <1399962220-27617-1-git-send-email-s.hauer@pengutronix.de> References: <1399962220-27617-1-git-send-email-s.hauer@pengutronix.de> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH 2/2] boot: iterate over directories in alphabetical order To: barebox@lists.infradead.org When iterating over directories in order to find boot scripts do this alphabetically to get a predictable order. This can be done with glob() rather than readdir(). Signed-off-by: Sascha Hauer --- commands/boot.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/commands/boot.c b/commands/boot.c index 468d473..a23ffb1 100644 --- a/commands/boot.c +++ b/commands/boot.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -129,10 +130,10 @@ static int bootscript_create_entry(struct blspec *blspec, const char *name) static int bootscript_scan_path(struct blspec *blspec, const char *path) { struct stat s; - DIR *dir; - struct dirent *d; - int ret; + char *files; + int ret, i; int found = 0; + glob_t globb; ret = stat(path, &s); if (ret) @@ -145,25 +146,24 @@ static int bootscript_scan_path(struct blspec *blspec, const char *path) return 1; } - dir = opendir(path); - if (!dir) - return -errno; + files = asprintf("%s/*", path); + + glob(files, 0, NULL, &globb); - while ((d = readdir(dir))) { - char *bootscript_path; + for (i = 0; i < globb.gl_pathc; i++) { + char *bootscript_path = globb.gl_pathv[i];; - if (*d->d_name == '.') + if (*basename(bootscript_path) == '.') continue; - bootscript_path = asprintf("%s/%s", path, d->d_name); bootscript_create_entry(blspec, bootscript_path); found++; - free(bootscript_path); } - ret = found; + globfree(&globb); + free(files); - closedir(dir); + ret = found; return ret; } -- 2.0.0.rc0 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox