diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2013-10-05 08:12:40 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2013-10-05 08:12:40 +0000 |
commit | 38f5e5f3973c4ee9eb77d669c868edfd6fc45faa (patch) | |
tree | bc4a137a72c7fd3babd337e9855fc3405a74d9d3 /usr.bin/tmux/tmux.c | |
parent | 3fe1d02207f2edb58531d86db67f0f31000c3dc9 (diff) |
Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().
Diffstat (limited to 'usr.bin/tmux/tmux.c')
-rw-r--r-- | usr.bin/tmux/tmux.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c index 7fae055b7ee..efa5ed3e365 100644 --- a/usr.bin/tmux/tmux.c +++ b/usr.bin/tmux/tmux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.c,v 1.120 2013/04/24 10:01:32 nicm Exp $ */ +/* $OpenBSD: tmux.c,v 1.121 2013/10/05 08:12:39 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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); } |