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>
This commit is contained in:
parent
a4987365a5
commit
37db9c61f7
|
@ -23,6 +23,7 @@
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <clock.h>
|
#include <clock.h>
|
||||||
#include <boot.h>
|
#include <boot.h>
|
||||||
|
#include <glob.h>
|
||||||
#include <menu.h>
|
#include <menu.h>
|
||||||
#include <fs.h>
|
#include <fs.h>
|
||||||
#include <complete.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)
|
static int bootscript_scan_path(struct blspec *blspec, const char *path)
|
||||||
{
|
{
|
||||||
struct stat s;
|
struct stat s;
|
||||||
DIR *dir;
|
char *files;
|
||||||
struct dirent *d;
|
int ret, i;
|
||||||
int ret;
|
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
glob_t globb;
|
||||||
|
|
||||||
ret = stat(path, &s);
|
ret = stat(path, &s);
|
||||||
if (ret)
|
if (ret)
|
||||||
|
@ -145,25 +146,24 @@ static int bootscript_scan_path(struct blspec *blspec, const char *path)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dir = opendir(path);
|
files = asprintf("%s/*", path);
|
||||||
if (!dir)
|
|
||||||
return -errno;
|
|
||||||
|
|
||||||
while ((d = readdir(dir))) {
|
glob(files, 0, NULL, &globb);
|
||||||
char *bootscript_path;
|
|
||||||
|
|
||||||
if (*d->d_name == '.')
|
for (i = 0; i < globb.gl_pathc; i++) {
|
||||||
|
char *bootscript_path = globb.gl_pathv[i];;
|
||||||
|
|
||||||
|
if (*basename(bootscript_path) == '.')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bootscript_path = asprintf("%s/%s", path, d->d_name);
|
|
||||||
bootscript_create_entry(blspec, bootscript_path);
|
bootscript_create_entry(blspec, bootscript_path);
|
||||||
found++;
|
found++;
|
||||||
free(bootscript_path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = found;
|
globfree(&globb);
|
||||||
|
free(files);
|
||||||
|
|
||||||
closedir(dir);
|
ret = found;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue