diff options
author | Michael Pavone <pavone@retrodev.com> | 2015-11-06 12:19:39 -0800 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2015-11-06 12:19:39 -0800 |
commit | 70be447f74b87c11557d2b5b1463005fddb0495a (patch) | |
tree | 9c871702bd0b40fd1ecb05bcb27dd824f9eb8c48 /util.c | |
parent | 60f60cd2c5236b0ba5654174c5faeb4a2d218fc9 (diff) |
Menu ROM now pulls real file names from the OS rather than using a fake list
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -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 <dirent.h> + +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 |