tweaks: check in a single place for files that should not be opened
This commit is contained in:
24
src/files.c
24
src/files.c
@@ -411,6 +411,7 @@ bool open_buffer(const char *filename, bool new_buffer)
|
|||||||
{
|
{
|
||||||
char *realname;
|
char *realname;
|
||||||
/* The filename after tilde expansion. */
|
/* The filename after tilde expansion. */
|
||||||
|
struct stat fileinfo;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int rc;
|
int rc;
|
||||||
/* rc == -2 means that we have a new file. -1 means that the
|
/* rc == -2 means that we have a new file. -1 means that the
|
||||||
@@ -429,15 +430,18 @@ bool open_buffer(const char *filename, bool new_buffer)
|
|||||||
|
|
||||||
realname = real_dir_from_tilde(filename);
|
realname = real_dir_from_tilde(filename);
|
||||||
|
|
||||||
/* When the given filename refers to a directory, don't try to open it. */
|
/* Don't try to open directories, character files, or block files. */
|
||||||
if (*filename != '\0') {
|
if (*filename != '\0' && stat(realname, &fileinfo) == 0) {
|
||||||
struct stat fileinfo;
|
if (S_ISDIR(fileinfo.st_mode)) {
|
||||||
|
|
||||||
if (stat(realname, &fileinfo) == 0 && S_ISDIR(fileinfo.st_mode)) {
|
|
||||||
statusline(ALERT, _("\"%s\" is a directory"), realname);
|
statusline(ALERT, _("\"%s\" is a directory"), realname);
|
||||||
free(realname);
|
free(realname);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
if (S_ISCHR(fileinfo.st_mode) || S_ISBLK(fileinfo.st_mode)) {
|
||||||
|
statusline(ALERT, _("\"%s\" is a device file"), realname);
|
||||||
|
free(realname);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we're going to load into a new buffer, first create the new
|
/* If we're going to load into a new buffer, first create the new
|
||||||
@@ -929,16 +933,6 @@ int open_file(const char *filename, bool newfie, FILE **f)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Don't open directories, character files, or block files. */
|
|
||||||
if (S_ISDIR(fileinfo.st_mode) || S_ISCHR(fileinfo.st_mode) ||
|
|
||||||
S_ISBLK(fileinfo.st_mode)) {
|
|
||||||
statusline(ALERT, S_ISDIR(fileinfo.st_mode) ?
|
|
||||||
_("\"%s\" is a directory") :
|
|
||||||
_("\"%s\" is a device file"), filename);
|
|
||||||
free(full_filename);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (S_ISFIFO(fileinfo.st_mode))
|
if (S_ISFIFO(fileinfo.st_mode))
|
||||||
statusbar(_("Reading from FIFO..."));
|
statusbar(_("Reading from FIFO..."));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user