2002-04-30 13:14:59 +00:00
|
|
|
|
2002-05-07 12:06:32 +00:00
|
|
|
#include <sys/stat.h>
|
2002-05-07 11:35:03 +00:00
|
|
|
#include "dir.h"
|
2002-04-30 13:14:59 +00:00
|
|
|
|
2002-05-07 12:06:32 +00:00
|
|
|
#undef DIR
|
2002-04-30 13:14:59 +00:00
|
|
|
|
2002-05-07 12:06:32 +00:00
|
|
|
MYDIR *x11_opendir(char *name)
|
2002-04-30 13:14:59 +00:00
|
|
|
{
|
|
|
|
char buffer[256]; /* sufficiently big */
|
2002-05-07 12:06:32 +00:00
|
|
|
MYDIR *my = (MYDIR *)malloc(sizeof(MYDIR));
|
2002-04-30 13:14:59 +00:00
|
|
|
|
|
|
|
if(name[0] == '/') {
|
2002-05-06 06:17:32 +00:00
|
|
|
sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
|
2002-05-07 12:06:32 +00:00
|
|
|
my->dir=(DIR *)opendir(buffer);
|
2002-04-30 13:14:59 +00:00
|
|
|
}
|
2002-05-07 12:06:32 +00:00
|
|
|
else
|
|
|
|
my->dir=(DIR *)opendir(name);
|
|
|
|
|
|
|
|
my->name = (char *)strdup(name);
|
|
|
|
|
|
|
|
return my;
|
2002-04-30 13:14:59 +00:00
|
|
|
}
|
2002-05-05 10:28:23 +00:00
|
|
|
|
2002-05-07 12:06:32 +00:00
|
|
|
struct dirent *x11_readdir(MYDIR *dir)
|
2002-05-07 11:35:03 +00:00
|
|
|
{
|
2002-05-07 12:06:32 +00:00
|
|
|
char buffer[512]; /* sufficiently big */
|
2002-05-07 11:35:03 +00:00
|
|
|
static struct dirent secret;
|
2002-05-07 12:06:32 +00:00
|
|
|
struct stat s;
|
2002-05-07 11:35:03 +00:00
|
|
|
|
2002-05-07 12:06:32 +00:00
|
|
|
struct x11_dirent *x11 = (readdir)(dir->dir);
|
2002-05-07 11:35:03 +00:00
|
|
|
|
|
|
|
strcpy(secret.d_name, x11->d_name);
|
2002-05-07 12:06:32 +00:00
|
|
|
|
|
|
|
/* 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;
|
2002-05-07 11:35:03 +00:00
|
|
|
|
|
|
|
return &secret;
|
|
|
|
}
|
|
|
|
|
2002-05-07 12:06:32 +00:00
|
|
|
void x11_closedir(MYDIR *dir)
|
|
|
|
{
|
|
|
|
free(dir->name);
|
|
|
|
(closedir)(dir->dir);
|
|
|
|
|
|
|
|
free(dir);
|
|
|
|
}
|
|
|
|
|
2002-05-07 11:35:03 +00:00
|
|
|
|
2002-05-05 10:28:23 +00:00
|
|
|
int x11_open(char *name, int opts)
|
|
|
|
{
|
|
|
|
char buffer[256]; /* sufficiently big */
|
|
|
|
|
|
|
|
if(name[0] == '/') {
|
2002-05-06 06:17:32 +00:00
|
|
|
sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
|
2002-05-05 10:28:23 +00:00
|
|
|
|
2002-05-06 11:24:34 +00:00
|
|
|
debugf("We open the real file '%s'", buffer);
|
2002-05-05 10:28:23 +00:00
|
|
|
return open(buffer, opts);
|
|
|
|
}
|
|
|
|
return open(name, opts);
|
|
|
|
}
|