[PATCH 17/23] src: replace getcwd() with g_get_current_dir()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



commandhelper.c is not converted since this is a standalone
program only run on UNIX, so can rely on getcwd().

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/util/virfile.c |  5 +----
 tools/vsh.c        | 16 +++-------------
 2 files changed, 4 insertions(+), 17 deletions(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index d5e4d0a289..9787086f3d 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -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);
     }
diff --git a/tools/vsh.c b/tools/vsh.c
index a2f33e01aa..a36b6bfe23 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -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[] = {
-- 
2.24.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux