1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-28 05:00:59 +01:00

28010: use getcwd() as fallback

This commit is contained in:
Peter Stephenson 2010-06-14 11:48:06 +00:00
parent 27254b788f
commit 825c1a1141
3 changed files with 52 additions and 3 deletions

View file

@ -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)