summaryrefslogtreecommitdiff
path: root/arch/sandbox/cpu/os.c
diff options
context:
space:
mode:
authorStefan Brüns <stefan.bruens@rwth-aachen.de>2016-10-01 20:41:42 +0200
committerSimon Glass <sjg@chromium.org>2016-10-11 10:17:07 -0600
commitbf635ed091dee333f4458eec617a4124b51322fc (patch)
tree69f1406d8d13aced4dc1a404d3b3e550dc8593f3 /arch/sandbox/cpu/os.c
parentf189899c2f9ae2266ea4814cf14f138cc47e319f (diff)
sandbox/fs: Use readdir instead of deprecated readdir_r
Using readdir_r limits the maximum file name length and may even be unsafe, and is thus deprecated in since glibc 2.24. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Acked-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'arch/sandbox/cpu/os.c')
-rw-r--r--arch/sandbox/cpu/os.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 16af3f5eea..47622a599c 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -313,7 +313,7 @@ void os_dirent_free(struct os_dirent_node *node)
int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
{
- struct dirent entry, *result;
+ struct dirent *entry;
struct os_dirent_node *head, *node, *next;
struct stat buf;
DIR *dir;
@@ -337,12 +337,15 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
}
for (node = head = NULL;; node = next) {
- ret = readdir_r(dir, &entry, &result);
- if (ret || !result)
+ errno = 0;
+ entry = readdir(dir);
+ if (!entry) {
+ ret = errno;
break;
- next = malloc(sizeof(*node) + strlen(entry.d_name) + 1);
- if (dirlen + strlen(entry.d_name) > len) {
- len = dirlen + strlen(entry.d_name);
+ }
+ next = malloc(sizeof(*node) + strlen(entry->d_name) + 1);
+ if (dirlen + strlen(entry->d_name) > len) {
+ len = dirlen + strlen(entry->d_name);
fname = realloc(fname, len);
}
if (!next || !fname) {
@@ -352,8 +355,8 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
goto done;
}
next->next = NULL;
- strcpy(next->name, entry.d_name);
- switch (entry.d_type) {
+ strcpy(next->name, entry->d_name);
+ switch (entry->d_type) {
case DT_REG:
next->type = OS_FILET_REG;
break;