summaryrefslogtreecommitdiffstats
path: root/commands/boot.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-05-13 08:20:52 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-05-13 08:21:42 +0200
commit37db9c61f70a2fae9cf2dd002d9056cc017074d9 (patch)
tree0f5025edaa7b73561ef10b10033c98200a7f62ae /commands/boot.c
parenta4987365a51a469d7a67b06b208b2b3217840601 (diff)
downloadbarebox-37db9c61f70a2fae9cf2dd002d9056cc017074d9.tar.gz
barebox-37db9c61f70a2fae9cf2dd002d9056cc017074d9.tar.xz
boot: iterate over directories in alphabetical order
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 <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/boot.c')
-rw-r--r--commands/boot.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/commands/boot.c b/commands/boot.c
index 468d473882..a23ffb1527 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -23,6 +23,7 @@
#include <malloc.h>
#include <clock.h>
#include <boot.h>
+#include <glob.h>
#include <menu.h>
#include <fs.h>
#include <complete.h>
@@ -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;
}