提交 0b4598b1 编写于 作者: D Daniel P. Berrangé

src: replace getcwd() with g_get_current_dir()

commandhelper.c is not converted since this is a standalone
program only run on UNIX, so can rely on getcwd().
Reviewed-by: NFabiano Fidêncio <fidencio@redhat.com>
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 88121631
...@@ -3187,10 +3187,7 @@ virFileAbsPath(const char *path, char **abspath) ...@@ -3187,10 +3187,7 @@ virFileAbsPath(const char *path, char **abspath)
if (path[0] == '/') { if (path[0] == '/') {
*abspath = g_strdup(path); *abspath = g_strdup(path);
} else { } else {
g_autofree char *buf = getcwd(NULL, 0); g_autofree char *buf = g_get_current_dir();
if (buf == NULL)
return -1;
*abspath = g_strdup_printf("%s/%s", buf, path); *abspath = g_strdup_printf("%s/%s", buf, path);
} }
......
...@@ -3296,21 +3296,11 @@ const vshCmdInfo info_pwd[] = { ...@@ -3296,21 +3296,11 @@ const vshCmdInfo info_pwd[] = {
bool bool
cmdPwd(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) cmdPwd(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
{ {
char *cwd; g_autofree char *cwd = g_get_current_dir();
bool ret = true;
char ebuf[1024];
cwd = getcwd(NULL, 0); vshPrint(ctl, _("%s\n"), cwd);
if (!cwd) {
vshError(ctl, _("pwd: cannot get current directory: %s"),
virStrerror(errno, ebuf, sizeof(ebuf)));
ret = false;
} else {
vshPrint(ctl, _("%s\n"), cwd);
VIR_FREE(cwd);
}
return ret; return true;
} }
const vshCmdInfo info_quit[] = { const vshCmdInfo info_quit[] = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册