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

Diff for /src/usr.bin/mg/file.c between version 1.81 and 1.82

version 1.81, 2012/06/18 09:19:21 version 1.82, 2012/08/28 11:37:49
Line 207 
Line 207 
 readin(char *fname)  readin(char *fname)
 {  {
         struct mgwin    *wp;          struct mgwin    *wp;
           struct stat      statbuf;
         int      status, i, ro = FALSE;          int      status, i, ro = FALSE;
         PF      *ael;          PF      *ael;
           char    *dp;
   
         /* might be old */          /* might be old */
         if (bclear(curbp) != TRUE)          if (bclear(curbp) != TRUE)
Line 242 
Line 244 
         curbp->b_flag &= ~BFCHG;          curbp->b_flag &= ~BFCHG;
   
         /*          /*
          * We need to set the READONLY flag after we insert the file,           * Set the buffer READONLY flag if any of following are true:
          * unless the file is a directory.           *   1. file is a directory.
            *   2. file is read-only.
            *   3. file doesn't exist and directory is read-only.
          */           */
         if (access(fname, W_OK) && errno != ENOENT)          if (fisdir(fname) == TRUE) {
                 ro = TRUE;                  ro = TRUE;
         if (fisdir(fname) == TRUE)          } else if (access(fname, W_OK) == -1) {
                 ro = TRUE;                  if (errno != ENOENT)
                           ro = TRUE;
                   else if (errno == ENOENT) {
                           dp = dirname(fname);
                           if (stat(dp, &statbuf) == -1 && errno == ENOENT) {
                                   /* no read-only; like emacs */
                                   ewprintf("Parent directory missing");
                           } else if (access(dp, W_OK) == -1 &&
                               errno == EACCES) {
                                   ewprintf("File not found and directory"
                                       " write-protected");
                                   ro = TRUE;
                           }
                   }
           }
         if (ro == TRUE)          if (ro == TRUE)
                 curbp->b_flag |= BFREADONLY;                  curbp->b_flag |= BFREADONLY;
   

Legend:
Removed from v.1.81  
changed lines
  Added in v.1.82