mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
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:
parent
67e3bac583
commit
c8425f832c
1 changed files with 5 additions and 9 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue