diff options
author | 2017-02-14 18:13:05 +0000 | |
---|---|---|
committer | 2017-02-14 18:13:05 +0000 | |
commit | 527df7dd49b24ff83b46f68eec4e25ae659c9a03 (patch) | |
tree | 63a272f3a16ce8342f729800efdbadf87c78c30b /usr.bin/tmux/server-client.c | |
parent | Missing opening brace. Spotted by Hiltjo Posthuma. (diff) | |
download | wireguard-openbsd-527df7dd49b24ff83b46f68eec4e25ae659c9a03.tar.xz wireguard-openbsd-527df7dd49b24ff83b46f68eec4e25ae659c9a03.zip |
Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.
Diffstat (limited to 'usr.bin/tmux/server-client.c')
-rw-r--r-- | usr.bin/tmux/server-client.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 90eae6956dc..adaa332991b 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.212 2017/02/09 12:09:33 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.213 2017/02/14 18:13:05 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1655,3 +1655,32 @@ server_client_add_message(struct client *c, const char *fmt, ...) free(msg); } } + +/* Get client working directory. */ +const char * +server_client_get_cwd(struct client *c) +{ + struct session *s; + + if (c != NULL && c->session == NULL && c->cwd != NULL) + return (c->cwd); + if (c != NULL && (s = c->session) != NULL && s->cwd != NULL) + return (s->cwd); + return ("."); +} + +/* Resolve an absolute path or relative to client working directory. */ +char * +server_client_get_path(struct client *c, const char *file) +{ + char *path, resolved[PATH_MAX]; + + if (*file == '/') + path = xstrdup(file); + else + xasprintf(&path, "%s/%s", server_client_get_cwd(c), file); + if (realpath(path, resolved) == NULL) + return (path); + free(path); + return (xstrdup(resolved)); +} |