Mercurial > repos > blastem
comparison util.c @ 866:69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 06 Nov 2015 12:19:39 -0800 |
parents | 3eced113081c |
children | 54ffba3768d6 |
comparison
equal
deleted
inserted
replaced
865:305c85c0b954 | 866:69a6ec208111 |
---|---|
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
11 | 11 |
12 #include "blastem.h" //for headless global | 12 #include "blastem.h" //for headless global |
13 #include "render.h" //for render_errorbox | 13 #include "render.h" //for render_errorbox |
14 #include "util.h" | |
14 | 15 |
15 char * alloc_concat(char * first, char * second) | 16 char * alloc_concat(char * first, char * second) |
16 { | 17 { |
17 int flen = strlen(first); | 18 int flen = strlen(first); |
18 int slen = strlen(second); | 19 int slen = strlen(second); |
275 } | 276 } |
276 #endif | 277 #endif |
277 } | 278 } |
278 return exe_dir; | 279 return exe_dir; |
279 } | 280 } |
280 | 281 #include <dirent.h> |
281 #endif | 282 |
283 dir_entry *get_dir_list(char *path, size_t *numret) | |
284 { | |
285 DIR *d = opendir(path); | |
286 if (!d) { | |
287 if (numret) { | |
288 *numret = 0; | |
289 } | |
290 return NULL; | |
291 } | |
292 size_t storage = 64; | |
293 dir_entry *ret = malloc(sizeof(dir_entry) * storage); | |
294 size_t pos = 0; | |
295 struct dirent* entry; | |
296 while (entry = readdir(d)) | |
297 { | |
298 if (entry->d_type != DT_REG && entry->d_type != DT_LNK && entry->d_type != DT_DIR) { | |
299 continue; | |
300 } | |
301 if (pos == storage) { | |
302 storage = storage * 2; | |
303 ret = realloc(ret, sizeof(dir_entry) * storage); | |
304 } | |
305 ret[pos].name = strdup(entry->d_name); | |
306 ret[pos++].is_dir = entry->d_type == DT_DIR; | |
307 } | |
308 if (numret) { | |
309 *numret = pos; | |
310 } | |
311 return ret; | |
312 } | |
313 | |
314 void free_dir_list(dir_entry *list, size_t numentries) | |
315 { | |
316 for (size_t i = 0; i < numentries; i++) | |
317 { | |
318 free(list[i].name); | |
319 } | |
320 free(list); | |
321 } | |
322 | |
323 #endif |