aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Hoffmann <stefan991@gmail.com>2014-03-16 19:55:49 +0100
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-03 10:30:03 -0300
commitfa2b327e9ac5f9554781960a5bb613840d95cafc (patch)
tree3af64790cfa2de6a3fb30c0b7ee25b93d055b715 /src
parent5a2c9e123e4f42a037dbd652c6c42cae943a5654 (diff)
downloadrneovim-fa2b327e9ac5f9554781960a5bb613840d95cafc.tar.gz
rneovim-fa2b327e9ac5f9554781960a5bb613840d95cafc.tar.bz2
rneovim-fa2b327e9ac5f9554781960a5bb613840d95cafc.zip
cleaned up the readonly check in readfile()
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 62e2b6fac1..1e8d1fb039 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -472,16 +472,19 @@ readfile (
}
/*
- * check readonly by trying to open the file for writing
+ * Check readonly by trying to open the file for writing.
+ * If this fails, we know that the file is readonly.
*/
file_readonly = FALSE;
- if (read_stdin) {
- } else if (!read_buffer) {
- if (!newfile
- || readonlymode
- || (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0) {
+ if (!read_buffer && !read_stdin) {
+ if (!newfile || readonlymode) {
+ file_readonly = TRUE;
+ } else if ((fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0) {
+ // opening in readwrite mode failed => file is readonly
file_readonly = TRUE;
- /* try to open ro */
+ }
+ if (file_readonly == TRUE) {
+ // try to open readonly
fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0);
}
}