lwp_dir.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-08-24 linzhenxing the first version
  9. */
  10. #include <dfs.h>
  11. #include "lwp_dir.h"
  12. #ifdef RT_USING_LWP
  13. #include <lwp.h>
  14. #endif
  15. #ifdef DFS_USING_WORKDIR
  16. extern char working_directory[];
  17. #endif
  18. void lwp_dir_set(char *buf)
  19. {
  20. if(strlen(buf) >= DFS_PATH_MAX)
  21. {
  22. rt_kprintf("buf too long!\n");
  23. return ;
  24. }
  25. #ifdef RT_USING_LWP
  26. struct rt_lwp *lwp;
  27. lwp = (struct rt_lwp *)rt_thread_self()->lwp;
  28. if (lwp)
  29. rt_strncpy(lwp->working_directory, buf, DFS_PATH_MAX);
  30. else
  31. rt_strncpy(working_directory, buf, DFS_PATH_MAX);
  32. #else
  33. rt_strncpy(working_directory, buf, DFS_PATH_MAX);
  34. #endif
  35. return ;
  36. }
  37. char *lwp_dir_get(void)
  38. {
  39. char *dir_buf = RT_NULL;
  40. #ifdef RT_USING_LWP
  41. struct rt_lwp *lwp;
  42. lwp = (struct rt_lwp *)rt_thread_self()->lwp;
  43. if (lwp)
  44. dir_buf = &lwp->working_directory[0];
  45. else
  46. dir_buf = &working_directory[0];
  47. #else
  48. dir_buf = &working_directory[0];
  49. #endif
  50. return dir_buf;
  51. }