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

Function sys_readlink

components/lwp/lwp_syscall.c:8490–8538  ·  view source on GitHub ↗

* @brief Read the value of a symbolic link. * * This function reads the value of a symbolic link and stores it in the provided buffer. The value is the * path to which the symbolic link points. If the symbolic link is too long to fit in the provided buffer, * the function returns the number of bytes needed to store the entire path (not including the terminating null byte). * * @param[in] pa

Source from the content-addressed store, hash-verified

8488 * @see sys_symlink(), sys_lstat()
8489 */
8490ssize_t sys_readlink(char* path, char *buf, size_t bufsz)
8491{
8492 size_t len, copy_len;
8493 int err, rtn;
8494 char *copy_path;
8495
8496 len = lwp_user_strlen(path);
8497 if (len <= 0)
8498 {
8499 return -EFAULT;
8500 }
8501
8502 if (!lwp_user_accessable(buf, bufsz))
8503 {
8504 return -EINVAL;
8505 }
8506
8507 copy_path = (char*)rt_malloc(len + 1);
8508 if (!copy_path)
8509 {
8510 return -ENOMEM;
8511 }
8512
8513 copy_len = lwp_get_from_user(copy_path, path, len);
8514 copy_path[copy_len] = '\0';
8515
8516 char *link_fn = (char *)rt_malloc(DFS_PATH_MAX);
8517 if (link_fn)
8518 {
8519 err = dfs_file_readlink(copy_path, link_fn, DFS_PATH_MAX);
8520 if (err > 0)
8521 {
8522 buf[bufsz > err ? err : bufsz] = '\0';
8523 rtn = lwp_put_to_user(buf, link_fn, bufsz > err ? err : bufsz);
8524 }
8525 else
8526 {
8527 rtn = -EIO;
8528 }
8529 rt_free(link_fn);
8530 }
8531 else
8532 {
8533 rtn = -ENOMEM;
8534 }
8535
8536 rt_free(copy_path);
8537 return rtn;
8538}
8539
8540/**
8541 * @brief Set the CPU affinity mask of a process.

Callers

nothing calls this directly

Calls 7

lwp_user_strlenFunction · 0.85
lwp_user_accessableFunction · 0.85
rt_mallocFunction · 0.85
lwp_get_from_userFunction · 0.85
dfs_file_readlinkFunction · 0.85
lwp_put_to_userFunction · 0.85
rt_freeFunction · 0.85

Tested by

no test coverage detected