run_module.c 877 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * File : module.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-04-12 yi.qiu first version
  13. */
  14. #include <rtthread.h>
  15. #include <dfs_posix.h>
  16. #ifdef RT_USING_FINSH
  17. #include <finsh.h>
  18. static char buffer[4096];
  19. void run_module(const char* filename)
  20. {
  21. int fd, length;
  22. struct dfs_stat s;
  23. fd = open(filename, O_RDONLY, 0);
  24. length = read(fd, buffer, 4096);
  25. if (length == 0)
  26. {
  27. rt_kprintf("check: read file failed\n");
  28. close(fd);
  29. return;
  30. }
  31. rt_module_load(buffer, filename);
  32. }
  33. FINSH_FUNCTION_EXPORT(run_module, run module from file);
  34. #endif