dlopen.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * File : dlopen.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-11-17 yi.qiu first version
  13. */
  14. #include <rtthread.h>
  15. #include <rtm.h>
  16. #define MODULE_ROOT_DIR "/module/lib"
  17. void* dlopen(const char *filename, int flags)
  18. {
  19. rt_module_t module;
  20. char *fullpath;
  21. const char*def_path = MODULE_ROOT_DIR;
  22. /* check parameters */
  23. RT_ASSERT(filename != RT_NULL);
  24. if (filename[0] != '/') /* it's a absolute path, use it directly */
  25. {
  26. fullpath = rt_malloc(strlen(def_path) + strlen(filename) + 2);
  27. /* join path and file name */
  28. rt_snprintf(fullpath, strlen(def_path) + strlen(filename) + 2,
  29. "%s/%s", def_path, filename);
  30. }
  31. /* find in module list */
  32. module = rt_module_find(fullpath);
  33. if(module != RT_NULL) module->nref++;
  34. else module = rt_module_open(fullpath);
  35. rt_free(fullpath);
  36. return (void*)module;
  37. }
  38. RTM_EXPORT(dlopen)