From 194174a371b16dfc24960d1e33371c0a7ef1c2c2 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Fri, 27 Aug 2010 00:29:50 +0000 Subject: 2nd try: Introduce a small api for loading code (codecs,plugins) from disk/memory. It's a used by codec/plugin loading and vastly reduces code duplication. It's also a step forward in getting rid of libuisimulator in the application ports. Apparently sh needs linker symbols prefixed with _ even if they're referenced without from C code. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27902 a1c6a512-1295-4272-9138-f99709370657 --- uisimulator/common/io.c | 116 +++++++----------------------------------------- 1 file changed, 16 insertions(+), 100 deletions(-) (limited to 'uisimulator/common/io.c') diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index 4c0fa33be5..9862b4a7a2 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c @@ -58,6 +58,7 @@ #include "debug.h" #include "ata.h" /* for IF_MV2 et al. */ #include "rbpaths.h" +#include "load_code.h" /* keep this in sync with file.h! */ #undef MAX_PATH /* this avoids problems when building simulator */ @@ -520,6 +521,8 @@ int sim_fsync(int fd) #endif } + +#ifndef __PCTOOL__ #ifdef WIN32 /* sim-win32 */ #define dlopen(_x_, _y_) LoadLibraryW(UTF8_TO_OS(_x_)) @@ -530,118 +533,31 @@ int sim_fsync(int fd) #include #endif -void *sim_codec_load_ram(char* codecptr, int size, void **pd) -{ - void *hdr; - char path[MAX_PATH]; - int fd; - int codec_count; -#ifdef WIN32 - char buf[MAX_PATH]; -#endif - - *pd = NULL; - /* We have to create the dynamic link library file from ram so we - can simulate the codec loading. With voice and crossfade, - multiple codecs may be loaded at the same time, so we need - to find an unused filename */ - for (codec_count = 0; codec_count < 10; codec_count++) - { -#if (CONFIG_PLATFORM & PLATFORM_ANDROID) - /* we need that path fixed, since get_user_file_path() - * gives us the folder on the sdcard where we cannot load libraries - * from (no exec permissions) - */ - snprintf(path, sizeof(path), - "/data/data/org.rockbox/app_rockbox/libtemp_codec_%d.so", - codec_count); -#else - char name[MAX_PATH]; - const char *_name = get_user_file_path(ROCKBOX_DIR, 0, name, sizeof(name)); - snprintf(path, sizeof(path), "%s/_temp_codec%d.dll", get_sim_pathname(_name), codec_count); -#endif - fd = OPEN(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU); - if (fd >= 0) - break; /* Created a file ok */ - } - if (fd < 0) - { - DEBUGF("failed to open for write: %s\n", path); - return NULL; - } - - if (write(fd, codecptr, size) != size) - { - DEBUGF("write failed"); - return NULL; - } - close(fd); +void *lc_open(const char *filename, char *buf, size_t buf_size) +{ + const char *sim_path = get_sim_pathname(filename); + void *handle = _lc_open((const char*)UTF8_TO_OS(sim_path), buf, buf_size); - /* Now load the library. */ - *pd = dlopen(path, RTLD_NOW); - if (*pd == NULL) + if (handle == NULL) { - DEBUGF("failed to load %s\n", path); -#ifdef WIN32 - FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, - buf, sizeof buf, NULL); - DEBUGF("dlopen(%s): %s\n", path, buf); -#else - DEBUGF("dlopen(%s): %s\n", path, dlerror()); -#endif - return NULL; + DEBUGF("failed to load %s\n", filename); + DEBUGF("lc_open(%s): %s\n", filename, lc_last_error()); } - - hdr = dlsym(*pd, "__header"); - if (!hdr) - hdr = dlsym(*pd, "___header"); - - return hdr; /* maybe NULL if symbol not present */ + return handle; } -void sim_codec_close(void *pd) +void *lc_get_header(void *handle) { - dlclose(pd); -} - -void *sim_plugin_load(char *plugin, void **pd) -{ - void *hdr; - char path[MAX_PATH]; -#ifdef WIN32 - char buf[MAX_PATH]; -#endif - - snprintf(path, sizeof(path), "%s", get_sim_pathname(plugin)); - - *pd = NULL; - - *pd = dlopen(path, RTLD_NOW); - if (*pd == NULL) { - DEBUGF("failed to load %s\n", plugin); -#ifdef WIN32 - FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, - buf, sizeof(buf), NULL); - DEBUGF("dlopen(%s): %s\n", path, buf); -#else - DEBUGF("dlopen(%s): %s\n", path, dlerror()); -#endif - return NULL; - } - - hdr = dlsym(*pd, "__header"); - if (!hdr) - hdr = dlsym(*pd, "___header"); - - return hdr; /* maybe NULL if symbol not present */ + return _lc_get_header(handle); } -void sim_plugin_close(void *pd) +void lc_close(void *handle) { - dlclose(pd); + _lc_close(handle); } +#endif /* __PCTOOL__ */ #ifdef WIN32 static unsigned old_cp; -- cgit v1.2.3