Added VG_(getcwd_alloc)(), which is much easier to use than VG_(getcwd)().
(getcwd() is really a pretty stupid syscall)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1867 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/vg_mylibc.c b/coregrind/vg_mylibc.c
index 7fbf928..60e3b84 100644
--- a/coregrind/vg_mylibc.c
+++ b/coregrind/vg_mylibc.c
@@ -1212,6 +1212,25 @@
return VG_(is_kerror)(res) ? ((Char*)NULL) : (Char*)res;
}
+/* Alternative version that does allocate the memory. Easier to use. */
+Bool VG_(getcwd_alloc) ( Char** out )
+{
+ UInt size = 4;
+
+ *out = NULL;
+ while (True) {
+ *out = VG_(malloc)(size);
+ if (NULL == VG_(getcwd)(*out, size)) {
+ VG_(free)(*out);
+ if (size > 65535)
+ return False;
+ size *= 2;
+ } else {
+ return True;
+ }
+ }
+}
+
/* ---------------------------------------------------------------------
Misc functions looking for a proper home.