Repository: lucy
Updated Branches:
  refs/heads/solaris_fixes d6e669aa9 -> a049eda70


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/a049eda7
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/a049eda7
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/a049eda7

Branch: refs/heads/solaris_fixes
Commit: a049eda7089c0b0a28fefd944ea5c0310ef89a39
Parents: d6e669a
Author: Nick Wellnhofer <[email protected]>
Authored: Tue Aug 19 23:05:21 2014 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Tue Aug 19 23:07:18 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/a049eda7/core/Lucy/Store/FSFolder.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/FSFolder.c b/core/Lucy/Store/FSFolder.c
index 7892a20..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, 2048);
+    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