Repository: lucy
Updated Branches:
  refs/heads/master 049ae7319 -> fd955dd5c


POSIX compliant use of getcwd

POSIX says: If buf is a null pointer, the behavior of getcwd() is
unspecified.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/65ea04e4
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/65ea04e4
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/65ea04e4

Branch: refs/heads/master
Commit: 65ea04e4856c57d80faa6a9fd057f4691ae40c04
Parents: 049ae73
Author: Nick Wellnhofer <[email protected]>
Authored: Tue Aug 19 16:14:48 2014 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Tue Aug 19 23:29:42 2014 +0200

----------------------------------------------------------------------
 core/Lucy/Store/FSFolder.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/65ea04e4/core/Lucy/Store/FSFolder.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/FSFolder.c b/core/Lucy/Store/FSFolder.c
index 9d4d03f..f8940ce 100644
--- a/core/Lucy/Store/FSFolder.c
+++ b/core/Lucy/Store/FSFolder.c
@@ -404,10 +404,17 @@ static String*
 S_absolutify(String *path) {
     if (S_is_absolute(path)) { return Str_Clone(path); }
 
-    char *cwd = getcwd(NULL, 0);
+    char *cwd = NULL;
+    for (size_t buf_size = 256; buf_size <= 65536; buf_size *= 2) {
+        cwd = (char*)MALLOCATE(buf_size);
+        if (getcwd(cwd, buf_size)) { break; }
+        FREEMEM(cwd);
+        cwd = NULL;
+        if (errno != ERANGE) { THROW(ERR, "getcwd failed"); }
+    }
     if (!cwd) { THROW(ERR, "getcwd failed"); }
     String *abs_path = Str_newf("%s" CHY_DIR_SEP "%o", cwd, path);
-    free(cwd);
+    FREEMEM(cwd);
 
     return abs_path;
 }

Reply via email to