* @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
| 1097 | * @see sys_open(), sys_remove(), unlink() |
| 1098 | */ |
| 1099 | sysret_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. |
nothing calls this directly
no test coverage detected