summaryrefslogtreecommitdiff
path: root/src/fileio.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-10-03 17:04:37 +0200
committerBram Moolenaar <Bram@vim.org>2020-10-03 17:04:37 +0200
commitc8fe645c198e2ca55c4e3446efbbdb9b995c63ce (patch)
treefe1529e5520e4be8c901d981ecd3a102dd522f0f /src/fileio.c
parent588d241d44fc25ad4c5a635ee4fdeafdfcee0fde (diff)
downloadvim-git-c8fe645c198e2ca55c4e3446efbbdb9b995c63ce.tar.gz
patch 8.2.1793: not consistently giving the "is a directory" warningv8.2.1793
Problem: Not consistently giving the "is a directory" warning. Solution: Adjust check for illegal file name and directory. (Yasuhiro Matsumoto, closes #7067)
Diffstat (limited to 'src/fileio.c')
-rw-r--r--src/fileio.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/fileio.c b/src/fileio.c
index aa6596df6..83924b352 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -211,6 +211,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
@@ -310,22 +311,29 @@ readfile(
else
msg_scroll = TRUE; // don't overwrite previous file message
- /*
- * 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 the name is too long we might crash further on, quit here.
- */
if (fname != NULL && *fname != NUL)
{
- p = fname + STRLEN(fname);
- if (after_pathsep(fname, p) || 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(fname, fname + namelen))
+ {
+ filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0);
+ msg_end();
+ msg_scroll = msg_save;
+ return FAIL;
+ }
}
if (!read_stdin && !read_buffer && !read_fifo)
@@ -349,7 +357,7 @@ readfile(
if (S_ISDIR(perm))
{
- filemess(curbuf, fname, (char_u *)_("is a directory"), 0);
+ filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0);
retval = NOTDONE;
}
else
@@ -475,7 +483,7 @@ readfile(
perm = mch_getperm(fname); // check if the file exists
if (isdir_f)
{
- filemess(curbuf, sfname, (char_u *)_("is a directory"), 0);
+ filemess(curbuf, sfname, (char_u *)_(msg_is_a_directory), 0);
curbuf->b_p_ro = TRUE; // must use "w!" now
}
else