version 1.81, 2012/06/18 09:19:21 |
version 1.82, 2012/08/28 11:37:49 |
|
|
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) |
|
|
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; |
|
|