]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
src: replace getcwd() with g_get_current_dir()
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 20 Dec 2019 16:51:16 +0000 (16:51 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 3 Jan 2020 15:42:13 +0000 (15:42 +0000)
commandhelper.c is not converted since this is a standalone
program only run on UNIX, so can rely on getcwd().

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/util/virfile.c
tools/vsh.c

index d5e4d0a289f9e2b103ae2b674610d857d9bfcc55..9787086f3d390c48481b9d834b01ed46480535f4 100644 (file)
@@ -3187,10 +3187,7 @@ virFileAbsPath(const char *path, char **abspath)
     if (path[0] == '/') {
         *abspath = g_strdup(path);
     } else {
-        g_autofree char *buf = getcwd(NULL, 0);
-
-        if (buf == NULL)
-            return -1;
+        g_autofree char *buf = g_get_current_dir();
 
         *abspath = g_strdup_printf("%s/%s", buf, path);
     }
index a2f33e01aa631ff48046c462052be16a961c7fc9..a36b6bfe232552f03da553951e07669d0419201e 100644 (file)
@@ -3296,21 +3296,11 @@ const vshCmdInfo info_pwd[] = {
 bool
 cmdPwd(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
 {
-    char *cwd;
-    bool ret = true;
-    char ebuf[1024];
+    g_autofree char *cwd = g_get_current_dir();
 
-    cwd = getcwd(NULL, 0);
-    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);
-    }
+    vshPrint(ctl, _("%s\n"), cwd);
 
-    return ret;
+    return true;
 }
 
 const vshCmdInfo info_quit[] = {