* @brief Get the full path of a directory entry by combining mount point and relative path * * @param[in] dentry Pointer to the directory entry structure * * @return char* Newly allocated string containing full path, or NULL if allocation failed * * @note The caller is responsible for freeing the returned string using rt_free() * @note Handles path concatenation with or without additional '
| 363 | * @note Handles path concatenation with or without additional '/' separator |
| 364 | */ |
| 365 | char* dfs_dentry_full_path(struct dfs_dentry* dentry) |
| 366 | { |
| 367 | char *path = NULL; |
| 368 | |
| 369 | if (dentry && dentry->mnt) |
| 370 | { |
| 371 | int mnt_len = strlen(dentry->mnt->fullpath); |
| 372 | int path_len = strlen(dentry->pathname); |
| 373 | |
| 374 | path = (char *) rt_malloc(mnt_len + path_len + 3); |
| 375 | if (path) |
| 376 | { |
| 377 | if (dentry->pathname[0] == '/' || dentry->mnt->fullpath[mnt_len - 1] == '/') |
| 378 | { |
| 379 | rt_snprintf(path, mnt_len + path_len + 2, "%s%s", dentry->mnt->fullpath, |
| 380 | dentry->pathname); |
| 381 | } |
| 382 | else |
| 383 | { |
| 384 | rt_snprintf(path, mnt_len + path_len + 2, "%s/%s", dentry->mnt->fullpath, |
| 385 | dentry->pathname); |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | return path; |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * @brief Get the parent directory path of a dentry by combining mount point and path |
no test coverage detected