diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-02-14 18:13:06 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-02-14 18:13:06 +0000 |
commit | 9ff5dae92ef837b083712f4dec05aa8f9ae1dab7 (patch) | |
tree | aadb5eadf0fc03d856c095683f3cbe761914ce8e /usr.bin/tmux/server-client.c | |
parent | c354b31d48263e4d8dba4af52f82bb9202a4728b (diff) |
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)); +} |