aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/fileio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/fileio.c')
-rw-r--r--src/nvim/fileio.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index ed8b72e2be..1b4a89fb6c 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -350,6 +350,7 @@ readfile(
char_u *old_b_fname;
int using_b_ffname;
int using_b_fname;
+ static char *msg_is_a_directory = N_("is a directory");
au_did_filetype = false; // reset before triggering any autocommands
@@ -444,21 +445,31 @@ readfile(
else
msg_scroll = TRUE; /* don't overwrite previous file message */
- /*
- * If the name is too long we might crash further on, quit here.
- */
+ // If the name is too long we might crash further on, quit here.
if (fname != NULL && *fname != NUL) {
- if (STRLEN(fname) >= MAXPATHL) {
+ size_t namelen = STRLEN(fname);
+
+ // If the name is too long we might crash further on, quit here.
+ if (namelen >= MAXPATHL) {
filemess(curbuf, fname, (char_u *)_("Illegal file name"), 0);
msg_end();
msg_scroll = msg_save;
return FAIL;
}
+
+ // If the name ends in a path separator, we can't open it. Check here,
+ // because reading the file may actually work, but then creating the
+ // swap file may destroy it! Reported on MS-DOS and Win 95.
+ if (after_pathsep((const char *)fname, (const char *)(fname + namelen))) {
+ filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0);
+ msg_end();
+ msg_scroll = msg_save;
+ return FAIL;
+ }
}
if (!read_buffer && !read_stdin && !read_fifo) {
perm = os_getperm((const char *)fname);
-#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 ...
@@ -474,7 +485,7 @@ readfile(
# endif
) {
if (S_ISDIR(perm)) {
- filemess(curbuf, fname, (char_u *)_("is a directory"), 0);
+ filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0);
} else {
filemess(curbuf, fname, (char_u *)_("is not a file"), 0);
}
@@ -482,7 +493,6 @@ readfile(
msg_scroll = msg_save;
return S_ISDIR(perm) ? NOTDONE : FAIL;
}
-#endif
}
/* Set default or forced 'fileformat' and 'binary'. */
@@ -541,13 +551,6 @@ readfile(
if (fd < 0) { // cannot open at all
msg_scroll = msg_save;
-#ifndef UNIX
- // On non-unix systems we can't open a directory, check here.
- if (os_isdir(fname)) {
- filemess(curbuf, sfname, (char_u *)_("is a directory"), 0);
- curbuf->b_p_ro = true; // must use "w!" now
- } else {
-#endif
if (!newfile) {
return FAIL;
}
@@ -605,9 +608,6 @@ readfile(
return FAIL;
}
-#ifndef UNIX
- }
-#endif
/*
* Only set the 'ro' flag for readonly files the first time they are