about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2010-06-14 11:48:06 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2010-06-14 11:48:06 +0000
commit825c1a1141a5724b980d0c1af7fe138ff7d10ae4 (patch)
treee080ee07d30d4dfad0f1ab5039e398f03738d907 /Src
parent27254b788f2ebeb4f6a2c7f308a9c774022070b0 (diff)
downloadzsh-825c1a1141a5724b980d0c1af7fe138ff7d10ae4.tar.gz
zsh-825c1a1141a5724b980d0c1af7fe138ff7d10ae4.tar.xz
zsh-825c1a1141a5724b980d0c1af7fe138ff7d10ae4.zip
28010: use getcwd() as fallback
Diffstat (limited to 'Src')
-rw-r--r--Src/compat.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/Src/compat.c b/Src/compat.c
index e72bf6268..e36de3219 100644
--- a/Src/compat.c
+++ b/Src/compat.c
@@ -420,9 +420,9 @@ zgetdir(struct dirsav *d)
 
 /*
  * Try to find the current directory.
+ * If we couldn't work it out internally, fall back to getcwd().
  * If it fails, fall back to pwd; if zgetcwd() is being used
  * to set pwd, pwd should be NULL and we just return ".".
- * We could fall back to getcwd() instead.
  */
 
 /**/
@@ -430,6 +430,23 @@ char *
 zgetcwd(void)
 {
     char *ret = zgetdir(NULL);
+#ifdef HAVE_GETCWD
+    if (!ret) {
+#ifdef GETCWD_CALLS_MALLOC
+	char *cwd = getcwd(NULL, 0);
+	if (cwd) {
+	    ret = dupstring(cwd);
+	    free(cwd);
+	}
+#else
+	char *cwdbuf = zalloc(PATH_MAX);
+	ret = getcwd(cwdbuf, PATH_MAX);
+	if (ret)
+	    ret = dupstring(ret);
+	free(cwdbuf);
+#endif /* GETCWD_CALLS_MALLOC */
+    }
+#endif /* HAVE_GETCWD */
     if (!ret)
 	ret = pwd;
     if (!ret)