dlopen.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 "/module/lib"
  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 absolute path, use it directly */
  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. /* find in module list */
  33. module = rt_module_find(fullpath);
  34. if(module != RT_NULL) module->nref++;
  35. else module = rt_module_open(fullpath);
  36. rt_free(fullpath);
  37. return (void*)module;
  38. }
  39. RTM_EXPORT(dlopen)