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

Function sys_lstat

components/lwp/lwp_syscall.c:4533–4578  ·  view source on GitHub ↗

* @brief Retrieves metadata about a file or symbolic link. * * This system call obtains metadata for the specified file or symbolic link and stores * it in the `buf` structure. Unlike `sys_stat`, if the specified path refers to a * symbolic link, this function retrieves information about the link itself, not the * target it points to. * * @param[in] file A pointer to the path of the file

Source from the content-addressed store, hash-verified

4531 * Always check inputs for validity before invoking this function.
4532 */
4533sysret_t sys_lstat(const char *file, struct stat *buf)
4534{
4535 int ret = 0;
4536 size_t len;
4537 size_t copy_len;
4538 char *copy_path;
4539 struct stat statbuff = {0};
4540
4541 if (!lwp_user_accessable((void *)buf, sizeof(struct stat)))
4542 {
4543 return -EFAULT;
4544 }
4545
4546 len = lwp_user_strlen(file);
4547 if (len <= 0)
4548 {
4549 return -EFAULT;
4550 }
4551
4552 copy_path = (char*)rt_malloc(len + 1);
4553 if (!copy_path)
4554 {
4555 return -ENOMEM;
4556 }
4557
4558 copy_len = lwp_get_from_user(copy_path, (void*)file, len);
4559 if (copy_len == 0)
4560 {
4561 rt_free(copy_path);
4562 return -EFAULT;
4563 }
4564 copy_path[copy_len] = '\0';
4565#ifdef RT_USING_DFS_V2
4566 ret = _SYS_WRAP(dfs_file_lstat(copy_path, &statbuff));
4567#else
4568 ret = _SYS_WRAP(stat(copy_path, &statbuff));
4569#endif
4570 rt_free(copy_path);
4571
4572 if (ret == 0)
4573 {
4574 lwp_put_to_user(buf, &statbuff, sizeof statbuff);
4575 }
4576
4577 return ret;
4578}
4579
4580sysret_t sys_notimpl(void)
4581{

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected