dlopen.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #include <string.h>
  17. #define MODULE_ROOT_DIR "/modules"
  18. void* dlopen(const char *filename, int flags)
  19. {
  20. rt_module_t module;
  21. char *fullpath;
  22. const char*def_path = MODULE_ROOT_DIR;
  23. /* check parameters */
  24. RT_ASSERT(filename != RT_NULL);
  25. if (filename[0] != '/') /* it's a relative path, prefix with MODULE_ROOT_DIR */
  26. {
  27. fullpath = rt_malloc(strlen(def_path) + strlen(filename) + 2);
  28. /* join path and file name */
  29. rt_snprintf(fullpath, strlen(def_path) + strlen(filename) + 2,
  30. "%s/%s", def_path, filename);
  31. }
  32. else
  33. {
  34. fullpath = (char*)filename; /* absolute path, use it directly */
  35. }
  36. /* find in module list */
  37. module = rt_module_find(fullpath);
  38. if(module != RT_NULL) module->nref++;
  39. else module = rt_module_open(fullpath);
  40. if(fullpath != filename)
  41. {
  42. rt_free(fullpath);
  43. }
  44. return (void*)module;
  45. }
  46. RTM_EXPORT(dlopen);