diff --git a/desmume/src/fs-linux.c b/desmume/src/fs-linux.c index 65a11f517..45fb50b6e 100644 --- a/desmume/src/fs-linux.c +++ b/desmume/src/fs-linux.c @@ -1,6 +1,7 @@ #include "fs.h" #include +#include #include #include #include @@ -8,8 +9,13 @@ void * FsReadFirst(const char * path, FsEntry * entry) { DIR * dir; struct dirent * e; + struct stat s; + + /* hack: reading a directory gives relative file names + * and there's no way to know that directory from + * DIR, so we're changing working directory... */ + chdir(path); - printf("reading %s\n", path); dir = opendir(path); if (!dir) return NULL; @@ -22,11 +28,17 @@ void * FsReadFirst(const char * path, FsEntry * entry) { strncpy(entry->cAlternateFileName, e->d_name, 12); entry->flags = 0; + stat(e->d_name, &s); + if (s.st_mode & S_IFDIR) { + entry->flags = FS_IS_DIR; + } + return dir; } int FsReadNext(void * search, FsEntry * entry) { struct dirent * e; + struct stat s; e = readdir(search); if (!e) @@ -36,6 +48,11 @@ int FsReadNext(void * search, FsEntry * entry) { strncpy(entry->cAlternateFileName, e->d_name, 12); entry->flags = 0; + stat(e->d_name, &s); + if (S_ISDIR(s.st_mode)) { + entry->flags = FS_IS_DIR; + } + return 1; }