MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / sys_stat

Function sys_stat

components/lwp/lwp_syscall.c:4464–4506  ·  view source on GitHub ↗

* @brief Retrieves information about a file or directory. * * This system call obtains metadata about the specified file or directory and stores it in * the `buf` structure. The metadata includes attributes such as file size, permissions, * ownership, and timestamps. * * @param[in] file A pointer to the path of the file or directory to be queried. * The path should be a

Source from the content-addressed store, hash-verified

4462 * Check all inputs before invoking this function to avoid potential issues.
4463 */
4464sysret_t sys_stat(const char *file, struct stat *buf)
4465{
4466 int ret = 0;
4467 size_t len;
4468 size_t copy_len;
4469 char *copy_path;
4470 struct stat statbuff = {0};
4471
4472 if (!lwp_user_accessable((void *)buf, sizeof(struct stat)))
4473 {
4474 return -EFAULT;
4475 }
4476
4477 len = lwp_user_strlen(file);
4478 if (len <= 0)
4479 {
4480 return -EFAULT;
4481 }
4482
4483 copy_path = (char*)rt_malloc(len + 1);
4484 if (!copy_path)
4485 {
4486 return -ENOMEM;
4487 }
4488
4489 copy_len = lwp_get_from_user(copy_path, (void*)file, len);
4490 if (copy_len == 0)
4491 {
4492 rt_free(copy_path);
4493 return -EFAULT;
4494 }
4495 copy_path[copy_len] = '\0';
4496
4497 ret = _SYS_WRAP(stat(copy_path, &statbuff));
4498 rt_free(copy_path);
4499
4500 if (ret == 0)
4501 {
4502 lwp_put_to_user(buf, &statbuff, sizeof statbuff);
4503 }
4504
4505 return ret;
4506}
4507
4508/**
4509 * @brief Retrieves metadata about a file or symbolic link.

Callers

nothing calls this directly

Calls 7

lwp_user_accessableFunction · 0.85
lwp_user_strlenFunction · 0.85
rt_mallocFunction · 0.85
lwp_get_from_userFunction · 0.85
rt_freeFunction · 0.85
lwp_put_to_userFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected