summaryrefslogtreecommitdiff
path: root/hw/9pfs/9p.c
diff options
context:
space:
mode:
Diffstat (limited to 'hw/9pfs/9p.c')
-rw-r--r--hw/9pfs/9p.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 1078cfdaa4..cdd44bdc82 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -2553,13 +2553,11 @@ static int coroutine_fn v9fs_complete_rename(V9fsPDU *pdu, V9fsFidState *fidp,
int32_t newdirfid,
V9fsString *name)
{
- char *end;
int err = 0;
V9fsPath new_path;
V9fsFidState *tfidp;
V9fsState *s = pdu->s;
V9fsFidState *dirfidp = NULL;
- char *old_name, *new_name;
v9fs_path_init(&new_path);
if (newdirfid != -1) {
@@ -2577,18 +2575,15 @@ static int coroutine_fn v9fs_complete_rename(V9fsPDU *pdu, V9fsFidState *fidp,
goto out;
}
} else {
- old_name = fidp->path.data;
- end = strrchr(old_name, '/');
- if (end) {
- end++;
- } else {
- end = old_name;
- }
- new_name = g_malloc0(end - old_name + name->size + 1);
- strncat(new_name, old_name, end - old_name);
- strncat(new_name + (end - old_name), name->data, name->size);
- err = v9fs_co_name_to_path(pdu, NULL, new_name, &new_path);
- g_free(new_name);
+ char *dir_name = g_path_get_dirname(fidp->path.data);
+ V9fsPath dir_path;
+
+ v9fs_path_init(&dir_path);
+ v9fs_path_sprintf(&dir_path, "%s", dir_name);
+ g_free(dir_name);
+
+ err = v9fs_co_name_to_path(pdu, &dir_path, name->data, &new_path);
+ v9fs_path_free(&dir_path);
if (err < 0) {
goto out;
}