forked from len0rd/rockbox
FS#9964 take 2. Including the whole patch is a good idea.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20133 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
6eea66fbc1
commit
b61f0c6884
1 changed files with 21 additions and 104 deletions
|
|
@ -140,7 +140,7 @@ extern int _wrmdir(const wchar_t*);
|
||||||
|
|
||||||
#ifdef HAVE_DIRCACHE
|
#ifdef HAVE_DIRCACHE
|
||||||
void dircache_remove(const char *name);
|
void dircache_remove(const char *name);
|
||||||
void dircache_rename(const char *oldpath, const char *newpath);
|
void dircache_rename(const char *oldname, const char *newname);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -264,11 +264,11 @@ static const char *get_sim_pathname(const char *name)
|
||||||
|
|
||||||
if(name[0] == '/')
|
if(name[0] == '/')
|
||||||
{
|
{
|
||||||
snprintf(buffer, sizeof(buffer), "%s%s",
|
snprintf(buffer, sizeof(buffer), "%s%s",
|
||||||
sim_root_dir != NULL ? sim_root_dir : SIMULATOR_DEFAULT_ROOT, name);
|
sim_root_dir != NULL ? sim_root_dir : SIMULATOR_DEFAULT_ROOT, name);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
DEBUGF("warning, filename lacks leading slash: %s\n", name);
|
fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", name);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
@ -308,7 +308,7 @@ struct sim_dirent *sim_readdir(MYDIR *dir)
|
||||||
strcpy((char *)secret.d_name, OS_TO_UTF8(x11->d_name));
|
strcpy((char *)secret.d_name, OS_TO_UTF8(x11->d_name));
|
||||||
|
|
||||||
/* build file name */
|
/* build file name */
|
||||||
snprintf(buffer, sizeof(buffer), "%s/%s",
|
snprintf(buffer, sizeof(buffer), "%s/%s",
|
||||||
get_sim_pathname(dir->name), secret.d_name);
|
get_sim_pathname(dir->name), secret.d_name);
|
||||||
STAT(buffer, &s); /* get info */
|
STAT(buffer, &s); /* get info */
|
||||||
|
|
||||||
|
|
@ -337,62 +337,30 @@ void sim_closedir(MYDIR *dir)
|
||||||
|
|
||||||
int sim_open(const char *name, int o)
|
int sim_open(const char *name, int o)
|
||||||
{
|
{
|
||||||
char buffer[MAX_PATH]; /* sufficiently big */
|
|
||||||
int opts = rockbox2sim(o);
|
int opts = rockbox2sim(o);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (num_openfiles >= MAX_OPEN_FILES)
|
if (num_openfiles >= MAX_OPEN_FILES)
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
#ifndef __PCTOOL__
|
ret = OPEN(get_sim_pathname(name), opts, 0666);
|
||||||
if(name[0] == '/')
|
|
||||||
{
|
|
||||||
snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name);
|
|
||||||
|
|
||||||
/* debugf("We open the real file '%s'\n", buffer); */
|
|
||||||
if (num_openfiles < MAX_OPEN_FILES)
|
|
||||||
{
|
|
||||||
ret = OPEN(buffer, opts, 0666);
|
|
||||||
if (ret >= 0) num_openfiles++;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "WARNING, bad file name lacks slash: %s\n",
|
|
||||||
name);
|
|
||||||
return -1;
|
|
||||||
#else
|
|
||||||
ret = OPEN(name, opts, 0666);
|
|
||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
num_openfiles++;
|
num_openfiles++;
|
||||||
return ret;
|
return ret;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int sim_close(int fd)
|
int sim_close(int fd)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
ret = CLOSE(fd);
|
ret = CLOSE(fd);
|
||||||
if (ret == 0) num_openfiles--;
|
if (ret == 0)
|
||||||
|
num_openfiles--;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sim_creat(const char *name)
|
int sim_creat(const char *name)
|
||||||
{
|
{
|
||||||
#ifndef __PCTOOL__
|
return OPEN(get_sim_pathname(name), O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||||
char buffer[MAX_PATH]; /* sufficiently big */
|
|
||||||
if(name[0] == '/')
|
|
||||||
{
|
|
||||||
snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name);
|
|
||||||
|
|
||||||
/* debugf("We create the real file '%s'\n", buffer); */
|
|
||||||
return OPEN(buffer, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
|
||||||
}
|
|
||||||
fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", name);
|
|
||||||
return -1;
|
|
||||||
#else
|
|
||||||
return OPEN(name, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t sim_read(int fd, void *buf, size_t count)
|
ssize_t sim_read(int fd, void *buf, size_t count)
|
||||||
|
|
@ -432,79 +400,28 @@ ssize_t sim_write(int fd, const void *buf, size_t count)
|
||||||
|
|
||||||
int sim_mkdir(const char *name)
|
int sim_mkdir(const char *name)
|
||||||
{
|
{
|
||||||
#ifdef __PCTOOL__
|
return MKDIR(get_sim_pathname(name), 0777);
|
||||||
return MKDIR(name, 0777);
|
|
||||||
#else
|
|
||||||
char buffer[MAX_PATH]; /* sufficiently big */
|
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name);
|
|
||||||
|
|
||||||
/* debugf("We create the real directory '%s'\n", buffer); */
|
|
||||||
return MKDIR(buffer, 0777);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int sim_rmdir(const char *name)
|
int sim_rmdir(const char *name)
|
||||||
{
|
{
|
||||||
#ifdef __PCTOOL__
|
return RMDIR(get_sim_pathname(name));
|
||||||
return RMDIR(name);
|
|
||||||
#else
|
|
||||||
char buffer[MAX_PATH]; /* sufficiently big */
|
|
||||||
if(name[0] == '/')
|
|
||||||
{
|
|
||||||
snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name);
|
|
||||||
|
|
||||||
/* debugf("We remove the real directory '%s'\n", buffer); */
|
|
||||||
return RMDIR(buffer);
|
|
||||||
}
|
|
||||||
return RMDIR(name);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int sim_remove(const char *name)
|
int sim_remove(const char *name)
|
||||||
{
|
{
|
||||||
#ifdef __PCTOOL__
|
|
||||||
return REMOVE(name);
|
|
||||||
#else
|
|
||||||
char buffer[MAX_PATH]; /* sufficiently big */
|
|
||||||
|
|
||||||
#ifdef HAVE_DIRCACHE
|
#ifdef HAVE_DIRCACHE
|
||||||
dircache_remove(name);
|
dircache_remove(name);
|
||||||
#endif
|
#endif
|
||||||
|
return REMOVE(get_sim_pathname(name));
|
||||||
if(name[0] == '/') {
|
|
||||||
snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name);
|
|
||||||
|
|
||||||
/* debugf("We remove the real file '%s'\n", buffer); */
|
|
||||||
return REMOVE(buffer);
|
|
||||||
}
|
|
||||||
return REMOVE(name);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int sim_rename(const char *oldpath, const char* newpath)
|
int sim_rename(const char *oldname, const char *newname)
|
||||||
{
|
{
|
||||||
#ifdef __PCTOOL__
|
|
||||||
return RENAME(oldpath, newpath);
|
|
||||||
#else
|
|
||||||
char buffer1[MAX_PATH];
|
|
||||||
char buffer2[MAX_PATH];
|
|
||||||
|
|
||||||
#ifdef HAVE_DIRCACHE
|
#ifdef HAVE_DIRCACHE
|
||||||
dircache_rename(oldpath, newpath);
|
dircache_rename(oldname, newname);
|
||||||
#endif
|
|
||||||
|
|
||||||
if(oldpath[0] == '/') {
|
|
||||||
snprintf(buffer1, sizeof(buffer1), "%s%s", get_sim_rootdir(),
|
|
||||||
oldpath);
|
|
||||||
snprintf(buffer2, sizeof(buffer2), "%s%s", get_sim_rootdir(),
|
|
||||||
newpath);
|
|
||||||
|
|
||||||
/* debugf("We rename the real file '%s' to '%s'\n", buffer1, buffer2); */
|
|
||||||
return RENAME(buffer1, buffer2);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
#endif
|
#endif
|
||||||
|
return RENAME(get_sim_pathname(oldname), get_sim_pathname(newname));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* rockbox off_t may be different from system off_t */
|
/* rockbox off_t may be different from system off_t */
|
||||||
|
|
@ -588,11 +505,10 @@ int sim_fsync(int fd)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TEMP_CODEC_FILE SIMULATOR_DEFAULT_ROOT "/_temp_codec%d.dll"
|
|
||||||
|
|
||||||
void *sim_codec_load_ram(char* codecptr, int size, void **pd)
|
void *sim_codec_load_ram(char* codecptr, int size, void **pd)
|
||||||
{
|
{
|
||||||
void *hdr;
|
void *hdr;
|
||||||
|
char name[MAX_PATH];
|
||||||
char path[MAX_PATH];
|
char path[MAX_PATH];
|
||||||
int fd;
|
int fd;
|
||||||
int codec_count;
|
int codec_count;
|
||||||
|
|
@ -608,8 +524,8 @@ void *sim_codec_load_ram(char* codecptr, int size, void **pd)
|
||||||
to find an unused filename */
|
to find an unused filename */
|
||||||
for (codec_count = 0; codec_count < 10; codec_count++)
|
for (codec_count = 0; codec_count < 10; codec_count++)
|
||||||
{
|
{
|
||||||
snprintf(path, sizeof(path), TEMP_CODEC_FILE, codec_count);
|
snprintf(name, sizeof(name), "/_temp_codec%d.dll", codec_count);
|
||||||
|
snprintf(path, sizeof(path), "%s", get_sim_pathname(name));
|
||||||
fd = OPEN(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU);
|
fd = OPEN(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
break; /* Created a file ok */
|
break; /* Created a file ok */
|
||||||
|
|
@ -620,7 +536,8 @@ void *sim_codec_load_ram(char* codecptr, int size, void **pd)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write(fd, codecptr, size) != size) {
|
if (write(fd, codecptr, size) != size)
|
||||||
|
{
|
||||||
DEBUGF("write failed");
|
DEBUGF("write failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -628,7 +545,7 @@ void *sim_codec_load_ram(char* codecptr, int size, void **pd)
|
||||||
|
|
||||||
/* Now load the library. */
|
/* Now load the library. */
|
||||||
*pd = dlopen(path, RTLD_NOW);
|
*pd = dlopen(path, RTLD_NOW);
|
||||||
if (*pd == NULL)
|
if (*pd == NULL)
|
||||||
{
|
{
|
||||||
DEBUGF("failed to load %s\n", path);
|
DEBUGF("failed to load %s\n", path);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
@ -661,7 +578,7 @@ void *sim_plugin_load(char *plugin, void **pd)
|
||||||
char buf[MAX_PATH];
|
char buf[MAX_PATH];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
snprintf(path, sizeof(path), SIMULATOR_DEFAULT_ROOT "%s", plugin);
|
snprintf(path, sizeof(path), "%s", get_sim_pathname(plugin));
|
||||||
|
|
||||||
*pd = NULL;
|
*pd = NULL;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue