[Libguestfs] [PATCH 15/16] tests: switch from get_current_dir_name to getcwd(0, NULL)

Pino Toscano ptoscano at redhat.com
Thu Oct 23 18:18:43 UTC 2014


get_current_dir_name exists on GNU libc only, so not portable.
On the other hand, while POSIX leaves a null buffer argument for getcwd
as unspecified behaviour, basically the most used/important Unix
implementations (GNU libc, FreeBSD's libc, etc) allow such value,
returning a new allocated buffer with the current directory.

In any case, the change just affects two tests, so even if it hits a
libc not implementing this behaviour for getcwd, only tests are
affected.
---
 tests/c-api/test-pwd.c                     | 2 +-
 tests/events/test-libvirt-auth-callbacks.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/c-api/test-pwd.c b/tests/c-api/test-pwd.c
index 60b978c..61b88ec 100644
--- a/tests/c-api/test-pwd.c
+++ b/tests/c-api/test-pwd.c
@@ -28,7 +28,7 @@
 int
 main (int argc, char *argv[])
 {
-  char *cwd = get_current_dir_name();
+  char *cwd = getcwd(NULL, 0);
   printf("%s", cwd);
 
   exit (EXIT_SUCCESS);
diff --git a/tests/events/test-libvirt-auth-callbacks.c b/tests/events/test-libvirt-auth-callbacks.c
index 7c26bbe..383f20f 100644
--- a/tests/events/test-libvirt-auth-callbacks.c
+++ b/tests/events/test-libvirt-auth-callbacks.c
@@ -70,9 +70,9 @@ main (int argc, char *argv[])
     exit (EXIT_FAILURE);
   }
 
-  cwd = get_current_dir_name ();
+  cwd = getcwd (NULL, 0);
   if (cwd == NULL) {
-    perror ("get_current_dir_name");
+    perror ("getcwd");
     exit (EXIT_FAILURE);
   }
 
-- 
1.9.3




More information about the Libguestfs mailing list