summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-load-buffer.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2011-10-23 08:34:01 +0000
committernicm <nicm@openbsd.org>2011-10-23 08:34:01 +0000
commit35a092d62738012b07bf5af85703df23fc920d33 (patch)
tree7f74e8847dd8233a69741636b8eaeb2c89a01433 /usr.bin/tmux/cmd-load-buffer.c
parentFor initial session, use size of command client even if detached. (diff)
downloadwireguard-openbsd-35a092d62738012b07bf5af85703df23fc920d33.tar.xz
wireguard-openbsd-35a092d62738012b07bf5af85703df23fc920d33.zip
Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).
Diffstat (limited to 'usr.bin/tmux/cmd-load-buffer.c')
-rw-r--r--usr.bin/tmux/cmd-load-buffer.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/usr.bin/tmux/cmd-load-buffer.c b/usr.bin/tmux/cmd-load-buffer.c
index 349fb771d25..cfa4fbbc285 100644
--- a/usr.bin/tmux/cmd-load-buffer.c
+++ b/usr.bin/tmux/cmd-load-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-load-buffer.c,v 1.18 2011/10/23 00:49:25 nicm Exp $ */
+/* $OpenBSD: cmd-load-buffer.c,v 1.19 2011/10/23 08:34:01 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -48,8 +48,9 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct args *args = self->args;
struct client *c = ctx->cmdclient;
+ struct session *s;
FILE *f;
- const char *path;
+ const char *path, *newpath, *wd;
char *pdata, *new_pdata, *cause;
size_t psize;
u_int limit;
@@ -93,6 +94,19 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
return (1);
}
+ if (c != NULL)
+ wd = c->cwd;
+ else if ((s = cmd_current_session(ctx, 0)) != NULL) {
+ wd = options_get_string(&s->options, "default-path");
+ if (*wd == '\0')
+ wd = s->cwd;
+ } else
+ wd = NULL;
+ if (wd != NULL && *wd != '\0') {
+ newpath = get_full_path(wd, path);
+ if (newpath != NULL)
+ path = newpath;
+ }
if ((f = fopen(path, "rb")) == NULL) {
ctx->error(ctx, "%s: %s", path, strerror(errno));
return (-1);