summaryrefslogtreecommitdiff
path: root/uisimulator/common/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/common/io.c')
-rw-r--r--uisimulator/common/io.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
index 78fb835785..7ea2d6878f 100644
--- a/uisimulator/common/io.c
+++ b/uisimulator/common/io.c
@@ -307,6 +307,78 @@ int sim_fsync(int fd)
307#include <dlfcn.h> 307#include <dlfcn.h>
308#endif 308#endif
309 309
310void *sim_codec_load_ram(char* codecptr, int size,
311 void* ptr2, int bufwrap, int *pd_fd)
312{
313 void *pd;
314 char *path = "archos/_temp_codec.dll";
315 int (*codec_start)(void * api);
316 int fd;
317 int copy_n;
318#ifdef WIN32
319 char buf[256];
320#endif
321
322 /* We have to create the dynamic link library file from ram
323 * so we could simulate the codec loading.
324 */
325 *pd_fd = -1;
326 fd = open(path, O_WRONLY | O_CREAT, S_IRWXU);
327 if (fd < 0) {
328 DEBUGF("failed to open for write: %s\n", path);
329 return NULL;
330 }
331
332 if (bufwrap == 0)
333 bufwrap = size;
334
335 copy_n = bufwrap < size ? bufwrap : size;
336 if (write(fd, codecptr, copy_n) != copy_n) {
337 DEBUGF("write failed");
338 return NULL;
339 }
340 size -= copy_n;
341 if (size > 0) {
342 if (write(fd, ptr2, size) != size) {
343 DEBUGF("write failed [2]");
344 return NULL;
345 }
346 }
347 close(fd);
348
349 /* Now load the library. */
350 pd = dlopen(path, RTLD_NOW);
351 if (!pd) {
352 DEBUGF("failed to load %s\n", path);
353#ifdef WIN32
354 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
355 buf, sizeof buf, NULL);
356 DEBUGF("dlopen(%s): %s\n", path, buf);
357#else
358 DEBUGF("dlopen(%s): %s\n", path, dlerror());
359#endif
360 dlclose(pd);
361 return NULL;
362 }
363
364 codec_start = dlsym(pd, "codec_start");
365 if (!codec_start) {
366 codec_start = dlsym(pd, "_codec_start");
367 if (!codec_start) {
368 dlclose(pd);
369 return NULL;
370 }
371 }
372
373 *pd_fd = (int)pd;
374 return codec_start;
375}
376
377void sim_codec_close(int pd)
378{
379 dlclose((void *)pd);
380}
381
310void *sim_plugin_load(char *plugin, int *fd) 382void *sim_plugin_load(char *plugin, int *fd)
311{ 383{
312 void* pd; 384 void* pd;