2002-05-13 15:23:30 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Daniel Stenberg
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2002-04-30 13:14:59 +00:00
|
|
|
|
2002-05-07 12:06:32 +00:00
|
|
|
#include <sys/stat.h>
|
2002-05-07 12:25:30 +00:00
|
|
|
#include <dirent.h>
|
2002-04-30 13:14:59 +00:00
|
|
|
|
2002-05-07 12:25:30 +00:00
|
|
|
#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */
|
|
|
|
#define dirent x11_dirent
|
|
|
|
#include "../../firmware/common/dir.h"
|
|
|
|
#undef dirent
|
|
|
|
|
|
|
|
#define SIMULATOR_ARCHOS_ROOT "archos"
|
|
|
|
|
|
|
|
struct mydir {
|
|
|
|
DIR *dir;
|
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct mydir MYDIR;
|
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-10 06:54:33 +00:00
|
|
|
DIR *dir;
|
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-10 06:54:33 +00:00
|
|
|
dir=(DIR *)opendir(buffer);
|
2002-04-30 13:14:59 +00:00
|
|
|
}
|
2002-05-07 12:06:32 +00:00
|
|
|
else
|
2002-05-10 06:54:33 +00:00
|
|
|
dir=(DIR *)opendir(name);
|
|
|
|
|
|
|
|
if(dir) {
|
|
|
|
MYDIR *my = (MYDIR *)malloc(sizeof(MYDIR));
|
|
|
|
my->dir = dir;
|
|
|
|
my->name = (char *)strdup(name);
|
2002-05-07 12:06:32 +00:00
|
|
|
|
2002-05-10 06:54:33 +00:00
|
|
|
return my;
|
|
|
|
}
|
|
|
|
/* failed open, return NULL */
|
|
|
|
return (MYDIR *)0;
|
2002-04-30 13:14:59 +00:00
|
|
|
}
|
2002-05-05 10:28:23 +00:00
|
|
|
|
2002-05-07 12:25:30 +00:00
|
|
|
struct x11_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 12:25:30 +00:00
|
|
|
static struct x11_dirent secret;
|
2002-05-07 12:06:32 +00:00
|
|
|
struct stat s;
|
2002-05-07 12:25:30 +00:00
|
|
|
struct dirent *x11 = (readdir)(dir->dir);
|
2002-05-07 11:35:03 +00:00
|
|
|
|
2002-05-07 12:25:30 +00:00
|
|
|
if(!x11)
|
2002-05-07 12:34:45 +00:00
|
|
|
return (struct x11_dirent *)0;
|
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-13 15:23:30 +00:00
|
|
|
debugf("We open the real file '%s'\n", buffer);
|
2002-05-05 10:28:23 +00:00
|
|
|
return open(buffer, opts);
|
|
|
|
}
|
|
|
|
return open(name, opts);
|
|
|
|
}
|