=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-save-buffer.c,v retrieving revision 1.20 retrieving revision 1.21 diff -c -r1.20 -r1.21 *** src/usr.bin/tmux/cmd-save-buffer.c 2013/10/10 12:00:22 1.20 --- src/usr.bin/tmux/cmd-save-buffer.c 2013/10/10 12:26:35 1.21 *************** *** 1,4 **** ! /* $OpenBSD: cmd-save-buffer.c,v 1.20 2013/10/10 12:00:22 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha --- 1,4 ---- ! /* $OpenBSD: cmd-save-buffer.c,v 1.21 2013/10/10 12:26:35 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha *************** *** 20,27 **** --- 20,29 ---- #include #include + #include #include #include + #include #include #include "tmux.h" *************** *** 54,70 **** cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; ! struct client *c; 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; FILE *f; - char *msg; - size_t msglen; if (!args_has(args, 'b')) { if ((pb = paste_get_top(&global_buffers)) == NULL) { --- 56,69 ---- cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; ! struct client *c = cmdq->client; struct session *s; struct paste_buffer *pb; ! const char *path; ! char *cause, *start, *end, *msg; ! size_t size, used, msglen; ! int cwd, fd, buffer; FILE *f; if (!args_has(args, 'b')) { if ((pb = paste_get_top(&global_buffers)) == NULL) { *************** *** 91,97 **** 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); --- 90,95 ---- *************** *** 101,128 **** 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"); else ! f = fopen(path, "wb"); ! umask(mask); if (f == NULL) { cmdq_error(cmdq, "%s: %s", path, strerror(errno)); return (CMD_RETURN_ERROR); } --- 99,124 ---- goto do_print; } ! 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; ! ! 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); }