aboutsummaryrefslogtreecommitdiff
path: root/cmd-load-buffer.c
diff options
context:
space:
mode:
authorThomas <thomas@xteddy.org>2013-10-11 14:33:29 +0100
committerThomas <thomas@xteddy.org>2013-10-11 14:33:29 +0100
commit7f479ffdce8f49f6c57d575b708c4cbe8cbe18df (patch)
treec0b1ddfb340c9bd59bbc02e83f30bf34aeb29a88 /cmd-load-buffer.c
parentc190c73240576aa2a8274a305844f1fa7fcb0e71 (diff)
parent4901d9ddc8d8c33ecdca363dcb67e66482745fa5 (diff)
downloadrtmux-7f479ffdce8f49f6c57d575b708c4cbe8cbe18df.tar.gz
rtmux-7f479ffdce8f49f6c57d575b708c4cbe8cbe18df.tar.bz2
rtmux-7f479ffdce8f49f6c57d575b708c4cbe8cbe18df.zip
Merge branch 'obsd-master' into mtemp
Diffstat (limited to 'cmd-load-buffer.c')
-rw-r--r--cmd-load-buffer.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c
index 3be14d6a..4acbab5e 100644
--- a/cmd-load-buffer.c
+++ b/cmd-load-buffer.c
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <errno.h>
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -39,7 +40,6 @@ const struct cmd_entry cmd_load_buffer_entry = {
CMD_BUFFER_USAGE " path",
0,
NULL,
- NULL,
cmd_load_buffer_exec
};
@@ -50,11 +50,11 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
struct client *c = cmdq->client;
struct session *s;
FILE *f;
- const char *path, *newpath, *wd;
+ const char *path;
char *pdata, *new_pdata, *cause;
size_t psize;
u_int limit;
- int ch, error, buffer, *buffer_ptr;
+ int ch, error, buffer, *buffer_ptr, cwd, fd;
if (!args_has(args, 'b'))
buffer = -1;
@@ -82,20 +82,17 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_WAIT);
}
- if (c != NULL)
- wd = c->cwd;
- else if ((s = cmd_current_session(cmdq, 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) {
+ if (c != NULL && c->session == NULL)
+ cwd = c->cwd;
+ else if ((s = cmd_current_session(cmdq, 0)) != NULL)
+ cwd = s->cwd;
+ else
+ cwd = AT_FDCWD;
+
+ if ((fd = openat(cwd, path, O_RDONLY)) == -1 ||
+ (f = fdopen(fd, "rb")) == NULL) {
+ if (fd != -1)
+ close(fd);
cmdq_error(cmdq, "%s: %s", path, strerror(errno));
return (CMD_RETURN_ERROR);
}