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

[Libguestfs] [PATCH v2 1/5] tests: switch away from xgetcwd



xgetcwd is used only in a test, so there is no need to pull a gnulib
module just for it.

Switch to use getcwd directly with a fixed buffer: the tests would have
failed with paths longer than 992 characters, as the libvirt_uri would
have been truncated.  Since there were no reports of issues, we can
assume that the current working directory will fit in 1024 characters;
adapt the size of libvirt_uri accordingly.
---
 tests/c-api/test-add-libvirt-dom.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/tests/c-api/test-add-libvirt-dom.c b/tests/c-api/test-add-libvirt-dom.c
index 10224d102..7c7c1bd26 100644
--- a/tests/c-api/test-add-libvirt-dom.c
+++ b/tests/c-api/test-add-libvirt-dom.c
@@ -28,8 +28,6 @@
 #include <libvirt/libvirt.h>
 #include <libvirt/virterror.h>
 
-#include "xgetcwd.h"
-
 #include "guestfs.h"
 #include "guestfs-utils.h"
 
@@ -76,11 +74,12 @@ main (int argc, char *argv[])
   virErrorPtr err;
   int r;
   char *backend;
-  char *cwd;
+  char cwd[1024];
   FILE *fp;
-  char libvirt_uri[1024];
+  char libvirt_uri[sizeof cwd + 64];
 
-  cwd = xgetcwd ();
+  if (getcwd (cwd, sizeof cwd) == NULL)
+    error (EXIT_FAILURE, errno, "getcwd");
 
   /* Create the guestfs handle. */
   g = guestfs_create ();
@@ -147,7 +146,6 @@ main (int argc, char *argv[])
 
   virDomainFree (dom);
   virConnectClose (conn);
-  free (cwd);
 
   unlink ("test-add-libvirt-dom.xml");
   unlink ("test-add-libvirt-dom-1.img");
-- 
2.21.0


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