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/cmd-load-buffer.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/cmd-load-buffer.c')
-rw-r--r-- | usr.bin/tmux/cmd-load-buffer.c | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/usr.bin/tmux/cmd-load-buffer.c b/usr.bin/tmux/cmd-load-buffer.c index 639bfaa7248..969f779889b 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.48 2017/01/06 13:26:09 nicm Exp $ */ +/* $OpenBSD: cmd-load-buffer.c,v 1.49 2017/02/14 18:13:05 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -57,11 +57,9 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item) struct args *args = self->args; struct cmd_load_buffer_data *cdata; struct client *c = item->client; - struct session *s; FILE *f; - const char *path, *bufname, *cwd; + const char *path, *bufname; char *pdata, *new_pdata, *cause, *file; - char resolved[PATH_MAX]; size_t psize; int ch, error; @@ -87,26 +85,11 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item) return (CMD_RETURN_WAIT); } - if (c != NULL && c->session == NULL && c->cwd != NULL) - cwd = c->cwd; - else if (c != NULL && (s = c->session) != NULL && s->cwd != NULL) - cwd = s->cwd; - else - cwd = "."; - - if (*path == '/') - file = xstrdup(path); - else - xasprintf(&file, "%s/%s", cwd, path); - if (realpath(file, resolved) == NULL && - strlcpy(resolved, file, sizeof resolved) >= sizeof resolved) { - cmdq_error(item, "%s: %s", file, strerror(ENAMETOOLONG)); - return (CMD_RETURN_ERROR); - } - f = fopen(resolved, "rb"); - free(file); + file = server_client_get_path(c, path); + f = fopen(file, "rb"); if (f == NULL) { - cmdq_error(item, "%s: %s", resolved, strerror(errno)); + cmdq_error(item, "%s: %s", file, strerror(errno)); + free(file); return (CMD_RETURN_ERROR); } @@ -122,13 +105,14 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item) pdata[psize++] = ch; } if (ferror(f)) { - cmdq_error(item, "%s: read error", resolved); + cmdq_error(item, "%s: read error", file); goto error; } if (pdata != NULL) pdata[psize] = '\0'; fclose(f); + free(file); if (paste_set(pdata, psize, bufname, &cause) != 0) { cmdq_error(item, "%s", cause); |