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

Function sys_chmod

components/lwp/lwp_syscall.c:10332–10361  ·  view source on GitHub ↗

* @brief Change file permissions. * * This function changes the permissions of a file or directory specified by the `pathname`. * The new permissions are specified using the `mode` argument, which is a bitwise OR of permission bits. * The permissions apply to the file owner, group, and others, depending on the value of `mode`. * * @param[in] pathname The path to the file or directory whose

Source from the content-addressed store, hash-verified

10330 * not the target file or directory.
10331 */
10332sysret_t sys_chmod(const char *pathname, mode_t mode)
10333{
10334 char *copy_file;
10335 size_t len_file, copy_len_file;
10336 struct dfs_attr attr = {0};
10337 int ret = 0;
10338
10339 len_file = lwp_user_strlen(pathname);
10340 if (len_file <= 0)
10341 {
10342 return -EFAULT;
10343 }
10344
10345 copy_file = (char*)rt_malloc(len_file + 1);
10346 if (!copy_file)
10347 {
10348 return -ENOMEM;
10349 }
10350
10351 copy_len_file = lwp_get_from_user(copy_file, (void *)pathname, len_file);
10352
10353 attr.st_mode = mode;
10354 attr.ia_valid |= ATTR_MODE_SET;
10355
10356 copy_file[copy_len_file] = '\0';
10357 ret = dfs_file_setattr(copy_file, &attr);
10358 rt_free(copy_file);
10359
10360 return (ret < 0 ? GET_ERRNO() : ret);
10361}
10362
10363/**
10364 * @brief Change the ownership of a file or directory.

Callers

nothing calls this directly

Calls 5

lwp_user_strlenFunction · 0.85
rt_mallocFunction · 0.85
lwp_get_from_userFunction · 0.85
dfs_file_setattrFunction · 0.85
rt_freeFunction · 0.85

Tested by

no test coverage detected