Added cflash support to gtk interface. fs-linux now detects directories.
This commit is contained in:
parent
8c70e4a8c2
commit
657bc38dec
|
@ -1,6 +1,7 @@
|
|||
#include "fs.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue