Use open(".")/fchdir() to save and restore current directory rather than

getcwd()/chdir().
pull/1/head
Nicholas Marriott 2013-10-05 09:14:11 +01:00
parent 13360ad541
commit d51b4f92d7
2 changed files with 11 additions and 5 deletions

12
tmux.c
View File

@ -130,16 +130,22 @@ areshell(const char *shell)
const char *
get_full_path(const char *wd, const char *path)
{
int fd;
static char newpath[MAXPATHLEN];
char oldpath[MAXPATHLEN];
if (getcwd(oldpath, sizeof oldpath) == NULL)
fd = open(".", O_RDONLY);
if (fd == -1)
return (NULL);
if (chdir(wd) != 0)
return (NULL);
if (realpath(path, newpath) != 0)
return (NULL);
chdir(oldpath);
if (fchdir(fd) != 0)
chdir("/");
close(fd);
return (newpath);
}