diff options
author | Thomas <thomas@xteddy.org> | 2013-10-11 14:33:29 +0100 |
---|---|---|
committer | Thomas <thomas@xteddy.org> | 2013-10-11 14:33:29 +0100 |
commit | 7f479ffdce8f49f6c57d575b708c4cbe8cbe18df (patch) | |
tree | c0b1ddfb340c9bd59bbc02e83f30bf34aeb29a88 /cmd-save-buffer.c | |
parent | c190c73240576aa2a8274a305844f1fa7fcb0e71 (diff) | |
parent | 4901d9ddc8d8c33ecdca363dcb67e66482745fa5 (diff) | |
download | rtmux-7f479ffdce8f49f6c57d575b708c4cbe8cbe18df.tar.gz rtmux-7f479ffdce8f49f6c57d575b708c4cbe8cbe18df.tar.bz2 rtmux-7f479ffdce8f49f6c57d575b708c4cbe8cbe18df.zip |
Merge branch 'obsd-master' into mtemp
Diffstat (limited to 'cmd-save-buffer.c')
-rw-r--r-- | cmd-save-buffer.c | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/cmd-save-buffer.c b/cmd-save-buffer.c index 52914a94..fc56dd8f 100644 --- a/cmd-save-buffer.c +++ b/cmd-save-buffer.c @@ -20,8 +20,11 @@ #include <sys/stat.h> #include <errno.h> +#include <fcntl.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> +#include <vis.h> #include "tmux.h" @@ -37,7 +40,6 @@ const struct cmd_entry cmd_save_buffer_entry = { "[-a] " CMD_BUFFER_USAGE " path", 0, NULL, - NULL, cmd_save_buffer_exec }; @@ -47,7 +49,6 @@ const struct cmd_entry cmd_show_buffer_entry = { CMD_BUFFER_USAGE, 0, NULL, - NULL, cmd_save_buffer_exec }; @@ -55,17 +56,14 @@ enum cmd_retval cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; - struct client *c; + struct client *c = cmdq->client; struct session *s; struct paste_buffer *pb; - const char *path, *newpath, *wd; - char *cause, *start, *end; - size_t size, used; - int buffer; - mode_t mask; + const char *path; + char *cause, *start, *end, *msg; + size_t size, used, msglen; + int cwd, fd, buffer; FILE *f; - char *msg; - size_t msglen; if (!args_has(args, 'b')) { if ((pb = paste_get_top(&global_buffers)) == NULL) { @@ -92,7 +90,6 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq) else path = args->argv[0]; if (strcmp(path, "-") == 0) { - c = cmdq->client; if (c == NULL) { cmdq_error(cmdq, "can't write to stdout"); return (CMD_RETURN_ERROR); @@ -102,28 +99,26 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq) goto do_print; } - c = cmdq->client; - 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; - } - - mask = umask(S_IRWXG | S_IRWXO); - if (args_has(self->args, 'a')) - f = fopen(path, "ab"); + if (c != NULL && c->session == NULL) + cwd = c->cwd; + else if ((s = cmd_current_session(cmdq, 0)) != NULL) + cwd = s->cwd; else - f = fopen(path, "wb"); - umask(mask); + cwd = AT_FDCWD; + + f = NULL; + if (args_has(self->args, 'a')) { + fd = openat(cwd, path, O_CREAT|O_RDWR|O_APPEND, 0600); + if (fd != -1) + f = fdopen(fd, "ab"); + } else { + fd = openat(cwd, path, O_CREAT|O_RDWR, 0600); + if (fd != -1) + f = fdopen(fd, "wb"); + } if (f == NULL) { + if (fd != -1) + close(fd); cmdq_error(cmdq, "%s: %s", path, strerror(errno)); return (CMD_RETURN_ERROR); } |