Index: uisimulator/common/io.c =================================================================== --- uisimulator/common/io.c (revision 20126) +++ uisimulator/common/io.c (working copy) @@ -140,7 +140,7 @@ #ifdef HAVE_DIRCACHE 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 @@ -258,31 +258,31 @@ } #ifndef __PCTOOL__ -static const char *get_sim_rootdir() +static const char *get_sim_pathname(const char *name) { - if (sim_root_dir != NULL) - return sim_root_dir; - return SIMULATOR_DEFAULT_ROOT; + static char buffer[MAX_PATH]; /* sufficiently big */ + + if(name[0] == '/') + { + snprintf(buffer, sizeof(buffer), "%s%s", + sim_root_dir != NULL ? sim_root_dir : SIMULATOR_DEFAULT_ROOT, name); + return buffer; + } + fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", name); + return name; } +#else +#define get_sim_pathname(name) name #endif MYDIR *sim_opendir(const char *name) { DIR_T *dir; -#ifndef __PCTOOL__ - char buffer[MAX_PATH]; /* sufficiently big */ + dir = (DIR_T *) OPENDIR(get_sim_pathname(name)); - if(name[0] == '/') + if (dir) { - snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name); - dir=(DIR_T *)OPENDIR(buffer); - } - else -#endif - dir=(DIR_T *)OPENDIR(name); - - if(dir) { MYDIR *my = (MYDIR *)malloc(sizeof(MYDIR)); my->dir = dir; my->name = (char *)malloc(strlen(name)+1); @@ -308,12 +308,8 @@ strcpy((char *)secret.d_name, OS_TO_UTF8(x11->d_name)); /* build file name */ -#ifdef __PCTOOL__ - snprintf(buffer, sizeof(buffer), "%s/%s", dir->name, secret.d_name); -#else - snprintf(buffer, sizeof(buffer), "%s/%s/%s", - get_sim_rootdir(), dir->name, secret.d_name); -#endif + snprintf(buffer, sizeof(buffer), "%s/%s", + get_sim_pathname(dir->name), secret.d_name); STAT(buffer, &s); /* get info */ #define ATTR_DIRECTORY 0x10 @@ -341,62 +337,30 @@ int sim_open(const char *name, int o) { - char buffer[MAX_PATH]; /* sufficiently big */ int opts = rockbox2sim(o); int ret; if (num_openfiles >= MAX_OPEN_FILES) return -2; -#ifndef __PCTOOL__ - 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); + ret = OPEN(get_sim_pathname(name), opts, 0666); if (ret >= 0) num_openfiles++; return ret; -#endif } int sim_close(int fd) { int ret; ret = CLOSE(fd); - if (ret == 0) num_openfiles--; + if (ret == 0) + num_openfiles--; return ret; } int sim_creat(const char *name) { -#ifndef __PCTOOL__ - 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 + return OPEN(get_sim_pathname(name), O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666); } ssize_t sim_read(int fd, void *buf, size_t count) @@ -436,79 +400,28 @@ int sim_mkdir(const char *name) { -#ifdef __PCTOOL__ - 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 + return MKDIR(get_sim_pathname(name), 0777); } int sim_rmdir(const char *name) { -#ifdef __PCTOOL__ - 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 + return RMDIR(get_sim_pathname(name)); } int sim_remove(const char *name) { -#ifdef __PCTOOL__ - return REMOVE(name); -#else - char buffer[MAX_PATH]; /* sufficiently big */ - #ifdef HAVE_DIRCACHE dircache_remove(name); #endif - - 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 + return REMOVE(get_sim_pathname(name)); } -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 - 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 + return RENAME(get_sim_pathname(oldname), get_sim_pathname(newname)); } /* rockbox off_t may be different from system off_t */ @@ -592,11 +505,10 @@ #include #endif -#define TEMP_CODEC_FILE SIMULATOR_DEFAULT_ROOT "/_temp_codec%d.dll" - void *sim_codec_load_ram(char* codecptr, int size, void **pd) { void *hdr; + char name[MAX_PATH]; char path[MAX_PATH]; int fd; int codec_count; @@ -612,8 +524,8 @@ to find an unused filename */ 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); if (fd >= 0) break; /* Created a file ok */ @@ -624,7 +536,8 @@ return NULL; } - if (write(fd, codecptr, size) != size) { + if (write(fd, codecptr, size) != size) + { DEBUGF("write failed"); return NULL; } @@ -632,7 +545,8 @@ /* Now load the library. */ *pd = dlopen(path, RTLD_NOW); - if (*pd == NULL) { + if (*pd == NULL) + { DEBUGF("failed to load %s\n", path); #ifdef WIN32 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, @@ -664,7 +578,7 @@ char buf[MAX_PATH]; #endif - snprintf(path, sizeof(path), SIMULATOR_DEFAULT_ROOT "%s", plugin); + snprintf(path, sizeof(path), "%s", get_sim_pathname(plugin)); *pd = NULL;