[BACK]Return to edit.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mail

Diff for /src/usr.bin/mail/edit.c between version 1.5 and 1.6

version 1.5, 1997/07/14 00:24:26 version 1.6, 1997/07/24 17:27:10
Line 155 
Line 155 
         register FILE *nf = NULL;          register FILE *nf = NULL;
         register int t;          register int t;
         time_t modtime;          time_t modtime;
         char *edit;          char *edit, tempname[PATHSIZE];
         struct stat statb;          struct stat statb;
         extern char *tempEdit;  
   
         if ((t = creat(tempEdit, readonly ? 0400 : 0600)) < 0) {          (void)snprintf(tempname, sizeof(tempname),
                 warn(tempEdit);              "%s/mail.ReXXXXXXXXXX", tmpdir);
           if ((t = mkstemp(tempname)) == -1 ||
               (nf = Fdopen(t, "w")) == NULL) {
                   warn(tempname);
                 goto out;                  goto out;
         }          }
         if ((nf = Fdopen(t, "w")) == NULL) {          if (readonly && fchmod(t, 0400) == -1) {
                 warn(tempEdit);                  warn(tempname);
                 (void)unlink(tempEdit);                  (void)rm(tempname);
                 goto out;                  goto out;
         }          }
         if (size >= 0)          if (size >= 0)
Line 181 
Line 183 
                 modtime = statb.st_mtime;                  modtime = statb.st_mtime;
         if (ferror(nf)) {          if (ferror(nf)) {
                 (void)Fclose(nf);                  (void)Fclose(nf);
                 warn(tempEdit);                  warn(tempname);
                 (void)unlink(tempEdit);                  (void)rm(tempname);
                 nf = NULL;                  nf = NULL;
                 goto out;                  goto out;
         }          }
         if (Fclose(nf) < 0) {          if (Fclose(nf) < 0) {
                 warn(tempEdit);                  warn(tempname);
                 (void)unlink(tempEdit);                  (void)rm(tempname);
                 nf = NULL;                  nf = NULL;
                 goto out;                  goto out;
         }          }
         nf = NULL;          nf = NULL;
         if ((edit = value(type == 'e' ? "EDITOR" : "VISUAL")) == NULL)          if ((edit = value(type == 'e' ? "EDITOR" : "VISUAL")) == NULL)
                 edit = type == 'e' ? _PATH_EX : _PATH_VI;                  edit = type == 'e' ? _PATH_EX : _PATH_VI;
         if (run_command(edit, 0, -1, -1, tempEdit, NULL, NULL) < 0) {          if (run_command(edit, 0, -1, -1, tempname, NULL, NULL) < 0) {
                 (void)unlink(tempEdit);                  (void)rm(tempname);
                 goto out;                  goto out;
         }          }
         /*          /*
Line 204 
Line 206 
          * temporary and return.           * temporary and return.
          */           */
         if (readonly) {          if (readonly) {
                 (void)unlink(tempEdit);                  (void)rm(tempname);
                 goto out;                  goto out;
         }          }
         if (stat(tempEdit, &statb) < 0) {          if (stat(tempname, &statb) < 0) {
                 warn(tempEdit);                  warn(tempname);
                 goto out;                  goto out;
         }          }
         if (modtime == statb.st_mtime) {          if (modtime == statb.st_mtime) {
                 (void)unlink(tempEdit);                  (void)rm(tempname);
                 goto out;                  goto out;
         }          }
         /*          /*
          * Now switch to new file.           * Now switch to new file.
          */           */
         if ((nf = Fopen(tempEdit, "a+")) == NULL) {          if ((nf = Fopen(tempname, "a+")) == NULL) {
                 warn(tempEdit);                  warn(tempname);
                 (void)unlink(tempEdit);                  (void)rm(tempname);
                 goto out;                  goto out;
         }          }
         (void)unlink(tempEdit);          (void)rm(tempname);
 out:  out:
         return(nf);          return(nf);
 }  }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6