From d51b4f92d7c9899694e9ef8334030ceb512cb2de Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sat, 5 Oct 2013 09:14:11 +0100 Subject: Use open(".")/fchdir() to save and restore current directory rather than getcwd()/chdir(). --- tmux.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'tmux.c') diff --git a/tmux.c b/tmux.c index 9c81cff5..4ff45d55 100644 --- a/tmux.c +++ b/tmux.c @@ -127,19 +127,25 @@ areshell(const char *shell) return (0); } -const char* +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); } -- cgit v1.2.3