Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions peripherals/fs/xfs_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,15 @@ static int16_t fs_getcwd(const struct xfs_engine_mount_t* engine, char* buffer,
// Rename file/directory
static int16_t fs_rename(const struct xfs_engine_mount_t* engine, const char* old_path, const char* new_path)
{
char* full_old_path = build_path(old_path);
char* full_new_path = build_path(new_path);
/* build_path() uses a single static buffer. Preserve the old path before
* resolving the new one, otherwise both arguments to rename() point at
* the new path. */
char full_old_path[PATH_MAX];
char full_new_path[PATH_MAX];
strncpy(full_old_path, build_path(old_path), sizeof(full_old_path) - 1);
full_old_path[sizeof(full_old_path) - 1] = '\0';
strncpy(full_new_path, build_path(new_path), sizeof(full_new_path) - 1);
full_new_path[sizeof(full_new_path) - 1] = '\0';
int ret = rename(full_old_path, full_new_path);

if (ret != 0) {
Expand Down
Loading