mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-08 01:04:06 +01:00
Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().
This commit is contained in:
parent
13360ad541
commit
d51b4f92d7
@ -135,7 +135,7 @@ error:
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
char *
|
||||||
osdep_get_cwd(int fd)
|
osdep_get_cwd(int fd)
|
||||||
{
|
{
|
||||||
int name[] = { CTL_KERN, KERN_PROC_CWD, 0 };
|
int name[] = { CTL_KERN, KERN_PROC_CWD, 0 };
|
||||||
|
14
tmux.c
14
tmux.c
@ -127,19 +127,25 @@ areshell(const char *shell)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char *
|
||||||
get_full_path(const char *wd, const char *path)
|
get_full_path(const char *wd, const char *path)
|
||||||
{
|
{
|
||||||
|
int fd;
|
||||||
static char newpath[MAXPATHLEN];
|
static char newpath[MAXPATHLEN];
|
||||||
char oldpath[MAXPATHLEN];
|
|
||||||
|
|
||||||
if (getcwd(oldpath, sizeof oldpath) == NULL)
|
fd = open(".", O_RDONLY);
|
||||||
|
if (fd == -1)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
if (chdir(wd) != 0)
|
if (chdir(wd) != 0)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
if (realpath(path, newpath) != 0)
|
if (realpath(path, newpath) != 0)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
chdir(oldpath);
|
|
||||||
|
if (fchdir(fd) != 0)
|
||||||
|
chdir("/");
|
||||||
|
close(fd);
|
||||||
|
|
||||||
return (newpath);
|
return (newpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user