Added cflash support to gtk interface. fs-linux now detects directories.

This commit is contained in:
yabause 2006-06-08 21:57:00 +00:00
parent 8c70e4a8c2
commit 657bc38dec
1 changed files with 18 additions and 1 deletions

View File

@ -1,6 +1,7 @@
#include "fs.h" #include "fs.h"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h> #include <dirent.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -8,8 +9,13 @@
void * FsReadFirst(const char * path, FsEntry * entry) { void * FsReadFirst(const char * path, FsEntry * entry) {
DIR * dir; DIR * dir;
struct dirent * e; 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); dir = opendir(path);
if (!dir) if (!dir)
return NULL; return NULL;
@ -22,11 +28,17 @@ void * FsReadFirst(const char * path, FsEntry * entry) {
strncpy(entry->cAlternateFileName, e->d_name, 12); strncpy(entry->cAlternateFileName, e->d_name, 12);
entry->flags = 0; entry->flags = 0;
stat(e->d_name, &s);
if (s.st_mode & S_IFDIR) {
entry->flags = FS_IS_DIR;
}
return dir; return dir;
} }
int FsReadNext(void * search, FsEntry * entry) { int FsReadNext(void * search, FsEntry * entry) {
struct dirent * e; struct dirent * e;
struct stat s;
e = readdir(search); e = readdir(search);
if (!e) if (!e)
@ -36,6 +48,11 @@ int FsReadNext(void * search, FsEntry * entry) {
strncpy(entry->cAlternateFileName, e->d_name, 12); strncpy(entry->cAlternateFileName, e->d_name, 12);
entry->flags = 0; entry->flags = 0;
stat(e->d_name, &s);
if (S_ISDIR(s.st_mode)) {
entry->flags = FS_IS_DIR;
}
return 1; return 1;
} }