diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2013-10-05 09:14:11 +0100 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2013-10-05 09:14:11 +0100 |
commit | d51b4f92d7c9899694e9ef8334030ceb512cb2de (patch) | |
tree | a7e64cc845642381b99a8b36dc8fbdc2b77461a0 | |
parent | 13360ad54157790cbbaab757f659cb6d8a4ce2c4 (diff) | |
download | rtmux-d51b4f92d7c9899694e9ef8334030ceb512cb2de.tar.gz rtmux-d51b4f92d7c9899694e9ef8334030ceb512cb2de.tar.bz2 rtmux-d51b4f92d7c9899694e9ef8334030ceb512cb2de.zip |
Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().
-rw-r--r-- | osdep-openbsd.c | 2 | ||||
-rw-r--r-- | tmux.c | 14 |
2 files changed, 11 insertions, 5 deletions
diff --git a/osdep-openbsd.c b/osdep-openbsd.c index 7be38a91..0a4c1445 100644 --- a/osdep-openbsd.c +++ b/osdep-openbsd.c @@ -135,7 +135,7 @@ error: return (NULL); } -char* +char * osdep_get_cwd(int fd) { int name[] = { CTL_KERN, KERN_PROC_CWD, 0 }; @@ -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); } |