extended the wrapper layer, we can't depend on much in the "real" dirent

struct since it differs too much between unixes. d_name is there, the rest
we get with stat() calls to simulate the target dirent properly


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@492 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Daniel Stenberg 2002-05-07 12:06:32 +00:00
parent 8ae29ff4b2
commit 27dfc7c14e
2 changed files with 45 additions and 9 deletions

View file

@ -20,6 +20,7 @@
#define dirent x11_dirent
#define readdir(x) x11_readdir(x)
#define opendir(x) x11_opendir(x)
#define closedir(x) x11_closedir(x)
/*
* The defines above should let us use the readdir() and opendir() in target
@ -38,6 +39,17 @@
#include "../../firmware/common/dir.h"
extern DIR *x11_opendir(char *name);
extern struct dirent* x11_readdir(DIR* dir);
#define SIMULATOR_ARCHOS_ROOT "archos"
struct mydir {
DIR *dir;
char *name;
};
typedef struct mydir MYDIR;
extern MYDIR *x11_opendir(char *name);
extern struct dirent* x11_readdir(MYDIR* dir);
extern void x11_closedir(MYDIR *dir);
#define DIR MYDIR

View file

@ -1,31 +1,55 @@
#include <sys/stat.h>
#include "dir.h"
#define SIMULATOR_ARCHOS_ROOT "archos"
#undef DIR
DIR *x11_opendir(char *name)
MYDIR *x11_opendir(char *name)
{
char buffer[256]; /* sufficiently big */
MYDIR *my = (MYDIR *)malloc(sizeof(MYDIR));
if(name[0] == '/') {
sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
return opendir(buffer);
my->dir=(DIR *)opendir(buffer);
}
return opendir(name);
else
my->dir=(DIR *)opendir(name);
my->name = (char *)strdup(name);
return my;
}
struct dirent *x11_readdir(DIR *dir)
struct dirent *x11_readdir(MYDIR *dir)
{
char buffer[512]; /* sufficiently big */
static struct dirent secret;
struct stat s;
struct x11_dirent *x11 = (readdir)(dir);
struct x11_dirent *x11 = (readdir)(dir->dir);
strcpy(secret.d_name, x11->d_name);
secret.attribute = (x11->d_type == DT_DIR)?ATTR_DIRECTORY:0;
/* build file name */
sprintf(buffer, SIMULATOR_ARCHOS_ROOT "%s/%s",
dir->name, x11->d_name);
stat(buffer, &s); /* get info */
secret.attribute = S_ISDIR(s.st_mode)?ATTR_DIRECTORY:0;
secret.size = s.st_size;
return &secret;
}
void x11_closedir(MYDIR *dir)
{
free(dir->name);
(closedir)(dir->dir);
free(dir);
}
int x11_open(char *name, int opts)
{