[BACK]Return to cmd-save-buffer.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/cmd-save-buffer.c between version 1.20 and 1.21

version 1.20, 2013/10/10 12:00:22 version 1.21, 2013/10/10 12:26:35
Line 20 
Line 20 
 #include <sys/stat.h>  #include <sys/stat.h>
   
 #include <errno.h>  #include <errno.h>
   #include <fcntl.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   #include <unistd.h>
 #include <vis.h>  #include <vis.h>
   
 #include "tmux.h"  #include "tmux.h"
Line 54 
Line 56 
 cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)  cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
 {  {
         struct args             *args = self->args;          struct args             *args = self->args;
         struct client           *c;          struct client           *c = cmdq->client;
         struct session          *s;          struct session          *s;
         struct paste_buffer     *pb;          struct paste_buffer     *pb;
         const char              *path, *newpath, *wd;          const char              *path;
         char                    *cause, *start, *end;          char                    *cause, *start, *end, *msg;
         size_t                   size, used;          size_t                   size, used, msglen;
         int                      buffer;          int                      cwd, fd, buffer;
         mode_t                   mask;  
         FILE                    *f;          FILE                    *f;
         char                    *msg;  
         size_t                   msglen;  
   
         if (!args_has(args, 'b')) {          if (!args_has(args, 'b')) {
                 if ((pb = paste_get_top(&global_buffers)) == NULL) {                  if ((pb = paste_get_top(&global_buffers)) == NULL) {
Line 91 
Line 90 
         else          else
                 path = args->argv[0];                  path = args->argv[0];
         if (strcmp(path, "-") == 0) {          if (strcmp(path, "-") == 0) {
                 c = cmdq->client;  
                 if (c == NULL) {                  if (c == NULL) {
                         cmdq_error(cmdq, "can't write to stdout");                          cmdq_error(cmdq, "can't write to stdout");
                         return (CMD_RETURN_ERROR);                          return (CMD_RETURN_ERROR);
Line 101 
Line 99 
                 goto do_print;                  goto do_print;
         }          }
   
         c = cmdq->client;          if (c != NULL && c->session == NULL)
         if (c != NULL)                  cwd = c->cwd;
                 wd = c->cwd;          else if ((s = cmd_current_session(cmdq, 0)) != NULL)
         else if ((s = cmd_current_session(cmdq, 0)) != NULL) {                  cwd = s->cwd;
                 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          else
                 f = fopen(path, "wb");                  cwd = AT_FDCWD;
         umask(mask);  
           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 (f == NULL) {
                   if (fd != -1)
                           close(fd);
                 cmdq_error(cmdq, "%s: %s", path, strerror(errno));                  cmdq_error(cmdq, "%s: %s", path, strerror(errno));
                 return (CMD_RETURN_ERROR);                  return (CMD_RETURN_ERROR);
         }          }

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21