aboutsummaryrefslogtreecommitdiff
path: root/server-client.c
diff options
context:
space:
mode:
authornicm <nicm>2017-02-14 18:13:05 +0000
committernicm <nicm>2017-02-14 18:13:05 +0000
commite340df2034c04591e3bbdcbcc22af1301cf74b09 (patch)
treed3d92f1bb528ba42eb0ea663f5094d8920c3fdd0 /server-client.c
parent4c2a78029d0cb307899be42d94d3c255b97fb15f (diff)
downloadrtmux-e340df2034c04591e3bbdcbcc22af1301cf74b09.tar.gz
rtmux-e340df2034c04591e3bbdcbcc22af1301cf74b09.tar.bz2
rtmux-e340df2034c04591e3bbdcbcc22af1301cf74b09.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 'server-client.c')
-rw-r--r--server-client.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/server-client.c b/server-client.c
index 1e349e38..4ea79e3d 100644
--- a/server-client.c
+++ b/server-client.c
@@ -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));
+}