Verifying that a named and existing file is a normal file, to avoid

opening an empty buffer when the name of a directory is specified. 


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5304 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Benno Schulenberg
2015-07-17 20:40:44 +00:00
parent 8cde95e170
commit 98ffb642f3
2 changed files with 22 additions and 0 deletions

View File

@@ -339,6 +339,21 @@ void open_buffer(const char *filename, bool undoable)
}
#endif
/* When the specified filename is not empty, and the thing exists,
* verify that it is a normal file. */
if (strcmp(filename, "") != 0) {
struct stat fileinfo;
if (stat(filename, &fileinfo) == 0 && !S_ISREG(fileinfo.st_mode)) {
if (S_ISDIR(fileinfo.st_mode))
statusbar(_("\"%s\" is a directory"), filename);
else
statusbar(_("\"%s\" is not a normal file"), filename);
beep();
return;
}
}
/* If we're going to load into a new buffer, first create the new
* buffer and lock the corresponding file. */
if (new_buffer) {