From 38f5e5f3973c4ee9eb77d669c868edfd6fc45faa Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sat, 5 Oct 2013 08:12:40 +0000 Subject: Use open(".")/fchdir() to save and restore current directory rather than getcwd()/chdir(). --- usr.bin/tmux/tmux.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'usr.bin/tmux/tmux.c') 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 @@ -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); } -- cgit v1.2.3