use g_path_get_dirname instead of dirname

Use g_path_get_basename to get the directory components of
a file name, and free its return when no longer needed.

Signed-off-by: Wei Jiangang <weijg.fnst@cn.fujitsu.com>
Message-Id: <1459997185-15669-3-git-send-email-weijg.fnst@cn.fujitsu.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Wei Jiangang 2016-04-07 10:46:24 +08:00 committed by Paolo Bonzini
parent 6b92bbfe81
commit 55ad781ca7
2 changed files with 5 additions and 2 deletions

View File

@ -89,7 +89,7 @@ char *os_find_datadir(void)
if (exec_dir == NULL) {
return NULL;
}
dir = dirname(exec_dir);
dir = g_path_get_dirname(exec_dir);
max_len = strlen(dir) +
MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1;
@ -103,6 +103,7 @@ char *os_find_datadir(void)
}
}
g_free(dir);
g_free(exec_dir);
return res;
}

View File

@ -299,9 +299,11 @@ void qemu_init_exec_dir(const char *argv0)
return;
}
}
dir = dirname(p);
dir = g_path_get_dirname(p);
pstrcpy(exec_dir, sizeof(exec_dir), dir);
g_free(dir);
}
char *qemu_get_exec_dir(void)