summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2013-10-05 08:12:39 +0000
committernicm <nicm>2013-10-05 08:12:39 +0000
commit3d8a8ea0c68d6ab343568559f7d5879170c2e78c (patch)
treed034a471e907966a47cd38e699d2dc9060bc1cf7
parent304ea079d2157b6625c960e0daa817213ba1ffd6 (diff)
Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().
-rw-r--r--tmux.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/tmux.c b/tmux.c
index b229967d..8726a55f 100644
--- a/tmux.c
+++ b/tmux.c
@@ -127,16 +127,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);
}