mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge #5185 from justinmk/readfile-perm
readfile(): Ensure `perm` for non-Unix.
This commit is contained in:
commit
852ebc6f0b
@ -282,11 +282,9 @@ readfile (
|
|||||||
int error = FALSE; /* errors encountered */
|
int error = FALSE; /* errors encountered */
|
||||||
int ff_error = EOL_UNKNOWN; /* file format with errors */
|
int ff_error = EOL_UNKNOWN; /* file format with errors */
|
||||||
long linerest = 0; /* remaining chars in line */
|
long linerest = 0; /* remaining chars in line */
|
||||||
#ifdef UNIX
|
|
||||||
int perm = 0;
|
int perm = 0;
|
||||||
|
#ifdef UNIX
|
||||||
int swap_mode = -1; /* protection bits for swap file */
|
int swap_mode = -1; /* protection bits for swap file */
|
||||||
#else
|
|
||||||
int perm;
|
|
||||||
#endif
|
#endif
|
||||||
int fileformat = 0; /* end-of-line format */
|
int fileformat = 0; /* end-of-line format */
|
||||||
int keep_fileformat = FALSE;
|
int keep_fileformat = FALSE;
|
||||||
@ -418,23 +416,21 @@ readfile (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!read_stdin && !read_buffer) {
|
if (!read_buffer && !read_stdin) {
|
||||||
#ifdef UNIX
|
|
||||||
/*
|
|
||||||
* On Unix it is possible to read a directory, so we have to
|
|
||||||
* check for it before os_open().
|
|
||||||
*/
|
|
||||||
perm = os_getperm(fname);
|
perm = os_getperm(fname);
|
||||||
if (perm >= 0 && !S_ISREG(perm) /* not a regular file ... */
|
#ifdef UNIX
|
||||||
|
// On Unix it is possible to read a directory, so we have to
|
||||||
|
// check for it before os_open().
|
||||||
|
if (perm >= 0 && !S_ISREG(perm) // not a regular file ...
|
||||||
# ifdef S_ISFIFO
|
# ifdef S_ISFIFO
|
||||||
&& !S_ISFIFO(perm) /* ... or fifo */
|
&& !S_ISFIFO(perm) // ... or fifo
|
||||||
# endif
|
# endif
|
||||||
# ifdef S_ISSOCK
|
# ifdef S_ISSOCK
|
||||||
&& !S_ISSOCK(perm) /* ... or socket */
|
&& !S_ISSOCK(perm) // ... or socket
|
||||||
# endif
|
# endif
|
||||||
# ifdef OPEN_CHR_FILES
|
# ifdef OPEN_CHR_FILES
|
||||||
&& !(S_ISCHR(perm) && is_dev_fd_file(fname))
|
&& !(S_ISCHR(perm) && is_dev_fd_file(fname))
|
||||||
/* ... or a character special file named /dev/fd/<n> */
|
// ... or a character special file named /dev/fd/<n>
|
||||||
# endif
|
# endif
|
||||||
) {
|
) {
|
||||||
if (S_ISDIR(perm))
|
if (S_ISDIR(perm))
|
||||||
@ -503,26 +499,21 @@ readfile (
|
|||||||
fd = os_open((char *)fname, O_RDONLY, 0);
|
fd = os_open((char *)fname, O_RDONLY, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd < 0) { /* cannot open at all */
|
if (fd < 0) { // cannot open at all
|
||||||
msg_scroll = msg_save;
|
msg_scroll = msg_save;
|
||||||
#ifndef UNIX
|
#ifndef UNIX
|
||||||
/*
|
// On non-unix systems we can't open a directory, check here.
|
||||||
* On non-unix systems we can't open a directory, check here.
|
|
||||||
*/
|
|
||||||
perm = os_getperm(fname); /* check if the file exists */
|
|
||||||
if (os_isdir(fname)) {
|
if (os_isdir(fname)) {
|
||||||
filemess(curbuf, sfname, (char_u *)_("is a directory"), 0);
|
filemess(curbuf, sfname, (char_u *)_("is a directory"), 0);
|
||||||
curbuf->b_p_ro = TRUE; /* must use "w!" now */
|
curbuf->b_p_ro = true; // must use "w!" now
|
||||||
} else
|
} else {
|
||||||
#endif
|
#endif
|
||||||
if (!newfile) {
|
if (!newfile) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (perm == UV_ENOENT) {
|
if (perm == UV_ENOENT) { // check if the file exists
|
||||||
/*
|
// Set the 'new-file' flag, so that when the file has
|
||||||
* Set the 'new-file' flag, so that when the file has
|
// been created by someone else, a ":w" will complain.
|
||||||
* been created by someone else, a ":w" will complain.
|
|
||||||
*/
|
|
||||||
curbuf->b_flags |= BF_NEW;
|
curbuf->b_flags |= BF_NEW;
|
||||||
|
|
||||||
/* Create a swap file now, so that other Vims are warned
|
/* Create a swap file now, so that other Vims are warned
|
||||||
@ -573,6 +564,9 @@ readfile (
|
|||||||
|
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
#ifndef UNIX
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Only set the 'ro' flag for readonly files the first time they are
|
* Only set the 'ro' flag for readonly files the first time they are
|
||||||
|
Loading…
Reference in New Issue
Block a user