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

Function sys_unlink

components/lwp/lwp_syscall.c:1099–1136  ·  view source on GitHub ↗

* @brief Removes a file or symbolic link from the filesystem. * * This system call deletes the file or symbolic link specified by `pathname`. * After the call, the file will be unlinked from the filesystem, meaning it will * no longer be accessible via its pathname. If the file is still open, it will * remain available to processes that have it open until all file descriptors are * closed. I

Source from the content-addressed store, hash-verified

1097 * @see sys_open(), sys_remove(), unlink()
1098 */
1099sysret_t sys_unlink(const char *pathname)
1100{
1101#ifdef ARCH_MM_MMU
1102 int ret = -1;
1103 rt_size_t len = 0;
1104 char *kname = RT_NULL;
1105
1106 len = lwp_user_strlen(pathname);
1107 if (!len)
1108 {
1109 return -EINVAL;
1110 }
1111
1112 kname = (char *)kmem_get(len + 1);
1113 if (!kname)
1114 {
1115 return -ENOMEM;
1116 }
1117
1118 if (lwp_get_from_user(kname, (void *)pathname, len + 1) != (len + 1))
1119 {
1120 kmem_put(kname);
1121 return -EINVAL;
1122 }
1123 ret = unlink(kname);
1124 if (ret < 0)
1125 {
1126 ret = GET_ERRNO();
1127 }
1128
1129 kmem_put(kname);
1130 return ret;
1131#else
1132 int ret = 0;
1133 ret = unlink(pathname);
1134 return (ret < 0 ? GET_ERRNO() : ret);
1135#endif
1136}
1137
1138/**
1139 * @brief Suspends execution for a specified amount of time.

Callers

nothing calls this directly

Calls 5

lwp_user_strlenFunction · 0.85
kmem_getFunction · 0.85
lwp_get_from_userFunction · 0.85
kmem_putFunction · 0.85
unlinkFunction · 0.50

Tested by

no test coverage detected