Fix non-standard getcwd() invocation

The POSIX standard specifies that a buffer should be supplied to
getcwd(), not doing so is undefined (or rather, platform-defined)
behavior. This was causing the getcwd errors on illumos (though not seen
on Solaris 11) reported in #3340

Closes #3340

(cherry picked from commit b495c68f28)
This commit is contained in:
Mahmoud Al-Qudsi 2017-09-26 09:49:54 -05:00
parent 67e3bac583
commit c8425f832c

View file

@ -137,18 +137,14 @@ bool wreaddir_for_dirs(DIR *dir, wcstring *out_name) {
}
const wcstring wgetcwd() {
wcstring retval;
char *res = getcwd(NULL, 0);
char cwd[NAME_MAX];
char *res = getcwd(cwd, sizeof(cwd));
if (res) {
retval = str2wcstring(res);
free(res);
} else {
debug(0, _(L"getcwd() failed with errno %d/%s"), errno, strerror(errno));
retval = wcstring();
return str2wcstring(res);
}
return retval;
debug(0, _(L"getcwd() failed with errno %d/%s"), errno, strerror(errno));
return wcstring();
}
int wchdir(const wcstring &dir) {