From 70be447f74b87c11557d2b5b1463005fddb0495a Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Fri, 6 Nov 2015 12:19:39 -0800 Subject: Menu ROM now pulls real file names from the OS rather than using a fake list --- util.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index 4b1e8c7..c4b25f5 100644 --- a/util.c +++ b/util.c @@ -11,6 +11,7 @@ #include "blastem.h" //for headless global #include "render.h" //for render_errorbox +#include "util.h" char * alloc_concat(char * first, char * second) { @@ -277,5 +278,46 @@ fallback: } return exe_dir; } +#include + +dir_entry *get_dir_list(char *path, size_t *numret) +{ + DIR *d = opendir(path); + if (!d) { + if (numret) { + *numret = 0; + } + return NULL; + } + size_t storage = 64; + dir_entry *ret = malloc(sizeof(dir_entry) * storage); + size_t pos = 0; + struct dirent* entry; + while (entry = readdir(d)) + { + if (entry->d_type != DT_REG && entry->d_type != DT_LNK && entry->d_type != DT_DIR) { + continue; + } + if (pos == storage) { + storage = storage * 2; + ret = realloc(ret, sizeof(dir_entry) * storage); + } + ret[pos].name = strdup(entry->d_name); + ret[pos++].is_dir = entry->d_type == DT_DIR; + } + if (numret) { + *numret = pos; + } + return ret; +} + +void free_dir_list(dir_entry *list, size_t numentries) +{ + for (size_t i = 0; i < numentries; i++) + { + free(list[i].name); + } + free(list); +} #endif -- cgit v1.2.3