run_module.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #include "string.h"
  17. #ifdef RT_USING_FINSH
  18. #include <finsh.h>
  19. static char buffer[4096];
  20. void run_module(const char* filename)
  21. {
  22. int fd, length;
  23. char *module_name;
  24. rt_memset(buffer, 0, 4096);
  25. fd = open(filename, O_RDONLY, 0);
  26. length = read(fd, buffer, 4096);
  27. if (length <= 0)
  28. {
  29. rt_kprintf("check: read file failed\n");
  30. close(fd);
  31. return;
  32. }
  33. rt_kprintf("read %d bytes from file\n", length);
  34. module_name = strrchr(filename, '/');
  35. rt_module_load(buffer, ++module_name);
  36. close(fd);
  37. }
  38. FINSH_FUNCTION_EXPORT(run_module, run module from file);
  39. #endif