diff --git a/uisimulator/x11/dir.h b/uisimulator/x11/dir.h index c7d557b475..3e83ce44b4 100644 --- a/uisimulator/x11/dir.h +++ b/uisimulator/x11/dir.h @@ -17,10 +17,26 @@ * ****************************************************************************/ +#define dirent x11_dirent +#define readdir(x) x11_readdir(x) +#define opendir(x) x11_opendir(x) + +/* + * The defines above should let us use the readdir() and opendir() in target + * code just as they're defined to work in target. They will then call our + * x11_* versions of the functions that'll work as wrappers for the actual + * host functions. + */ + #include #include -#define opendir(x) x11_opendir(x) +#undef dirent + + +#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */ -#define DIRENT_DEFINED /* prevent it from getting defined again */ #include "../../firmware/common/dir.h" + +extern DIR *x11_opendir(char *name); + diff --git a/uisimulator/x11/io.c b/uisimulator/x11/io.c index 2a94969ce3..0452d65ae8 100644 --- a/uisimulator/x11/io.c +++ b/uisimulator/x11/io.c @@ -1,5 +1,5 @@ -#include +#include "dir.h" #define SIMULATOR_ARCHOS_ROOT "archos" @@ -14,6 +14,19 @@ DIR *x11_opendir(char *name) return opendir(name); } +struct dirent *x11_readdir(DIR *dir) +{ + static struct dirent secret; + + struct x11_dirent *x11 = (readdir)(dir); + + strcpy(secret.d_name, x11->d_name); + secret.attribute = (x11->d_type == DT_DIR)?ATTR_DIRECTORY:0; + + return &secret; +} + + int x11_open(char *name, int opts) { char buffer[256]; /* sufficiently big */