Some more fixes to the linux filesystem driver, it seems to be

working now.
This commit is contained in:
yabause 2006-11-04 19:51:47 +00:00
parent 8ea9c268fb
commit 6265da362a
1 changed files with 29 additions and 14 deletions

View File

@ -6,35 +6,46 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
typedef struct {
DIR * dir;
char * path;
} FsLinuxDir;
const char FS_SEPARATOR = '/'; const char FS_SEPARATOR = '/';
void * FsReadFirst(const char * path, FsEntry * entry) { void * FsReadFirst(const char * path, FsEntry * entry) {
DIR * dir; FsLinuxDir * dir;
struct dirent * e; struct dirent * e;
struct stat s; struct stat s;
char buffer[1024];
DIR * tmp;
printf("reading %s\n", path); tmp = opendir(path);
if (!tmp)
/* 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);
dir = opendir(path);
if (!dir)
return NULL; return NULL;
e = readdir(dir); e = readdir(tmp);
if (!e) if (!e)
return NULL; return NULL;
dir = malloc(sizeof(FsLinuxDir));
dir->dir = tmp;
strcpy(entry->cFileName, e->d_name); strcpy(entry->cFileName, e->d_name);
// there's no 8.3 file names support on linux :) // there's no 8.3 file names support on linux :)
strcpy(entry->cAlternateFileName, ""); strcpy(entry->cAlternateFileName, "");
entry->flags = 0; entry->flags = 0;
/* 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);
getcwd(buffer, 1024);
dir->path = strdup(buffer);
stat(e->d_name, &s); stat(e->d_name, &s);
if (s.st_mode & S_IFDIR) { if (S_ISDIR(s.st_mode)) {
entry->flags = FS_IS_DIR; entry->flags = FS_IS_DIR;
} }
@ -42,10 +53,11 @@ void * FsReadFirst(const char * path, FsEntry * entry) {
} }
int FsReadNext(void * search, FsEntry * entry) { int FsReadNext(void * search, FsEntry * entry) {
FsLinuxDir * dir = search;
struct dirent * e; struct dirent * e;
struct stat s; struct stat s;
e = readdir(search); e = readdir(dir->dir);
if (!e) if (!e)
return 0; return 0;
@ -54,6 +66,8 @@ int FsReadNext(void * search, FsEntry * entry) {
strcpy(entry->cAlternateFileName, ""); strcpy(entry->cAlternateFileName, "");
entry->flags = 0; entry->flags = 0;
chdir(dir->path);
stat(e->d_name, &s); stat(e->d_name, &s);
if (S_ISDIR(s.st_mode)) { if (S_ISDIR(s.st_mode)) {
entry->flags = FS_IS_DIR; entry->flags = FS_IS_DIR;
@ -63,9 +77,10 @@ int FsReadNext(void * search, FsEntry * entry) {
} }
void FsClose(void * search) { void FsClose(void * search) {
DIR * dir = search; DIR * dir = ((FsLinuxDir *) search)->dir;
closedir(dir); closedir(dir);
free(search);
} }
int FsError(void) { int FsError(void) {